c++: fix missing file:line:column on "required from here" [PR122001]
PR diagnostics/122001 notes that in GCC 15 we emit:
<source>: In instantiation of 'void foo(T) [with T = std::nullptr_t]':
<source>:7:8: required from here
7 | foo(nullptr);
| ~~~^~~~~~~~~
<source>:3:7: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator+'
3 | 1 + t;
| ~~^~~
whereas in GCC 16 we emit:
<source>: In instantiation of 'void foo(T) [with T = std::nullptr_t]':
required from here
<source>:7:8:
7 | foo(nullptr);
| ~~~^~~~~~~~~
<source>:3:7: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator+'
3 | 1 + t;
| ~~^~~
where the "required from line" has lost its file:line:column prefix,
with the latter appearing on a follow line.
The root cause is that in
r15-5995-g339246fb9ef4ca I changed
cp/error.cc's print_instantiation_partial_context_line from using
print_location to using auto_context_line, so that the location
information would be better integrated with nested diagnostics,
and enabled this by default in
r16-3092-gd3fe5a560f0bcc.
text_sink::build_indent_prefix is returning the empty string for such
lines, rather than an indented bullet point.
This patch tweaks things so that such lines print the location before
the message at the top nesting level, and on a separate line at nested
nesting levels, and always the latter with
-fno-diagnostics-show-nesting.
gcc/cp/ChangeLog:
PR diagnostics/122001
* error.cc (auto_context_line::auto_context_line): Initialize
m_nesting_level and m_location_printed. Update the condition
for printing location in ctor to also do it at top-level
nesting level. Record into m_location_printed if we did
print the location.
(auto_context_line::~auto_context_line): Don't call print_location
if we already printed it in the ctor.
(auto_context_line::m_nesting_level): New field.
(auto_context_line::m_location_printed): New field.
gcc/testsuite/ChangeLog:
PR diagnostics/122001
* g++.dg/diagnostic/instantiation-context-pr122001-1.C: New test.
* g++.dg/diagnostic/instantiation-context-pr122001-2.C: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>