gcc/libstdc++-v3/testsuite/18_support/source_location
Jakub Jelinek 2132a36370 c++: Fix source_location inconsistency between calls from templates and non-templates [PR99672]
The srcloc19.C testcase shows inconsistency in
std::source_location::current() locations between calls from
templates and non-templates.  The location used by __builtin_source_location
comes in both cases from input_location which is set on it by bot_manip
when handling the default argument, called during finish_call_expr.
The problem is that in templates that input_location comes from the
CALL_EXPR we built earlier and that has the combined locus with
range between first character of the function name and closing paren
with caret on the opening paren, so something printed as caret as:
foobar ();
~~~~~~^~
But outside of templates, finish_call_expr is called when input_location
is just the closing paren token, i.e.
foobar ();
        ^
and only after that returns we create the combined location and set
the CALL_EXPR location to that.  So, it means std::source_location::current()
reports in templates the column of opening (, while outside of templates
closing ).

The following patch makes it consistent by creating the combined location
already before calling finish_call_expr and temporarily overriding
input_location to that.

2021-03-25  Jakub Jelinek  <jakub@redhat.com>

	PR c++/99672
	* parser.c (cp_parser_postfix_expression): For calls, create
	combined_loc and temporarily set input_location to it before
	calling finish_call_expr.

	* g++.dg/concepts/diagnostic2.C: Adjust expected caret line.
	* g++.dg/cpp1y/builtin_location.C (f4, n6): Move #line directives
	to match locus changes.
	* g++.dg/cpp2a/srcloc1.C: Adjust expected column numbers.
	* g++.dg/cpp2a/srcloc2.C: Likewise.
	* g++.dg/cpp2a/srcloc15.C: Likewise.
	* g++.dg/cpp2a/srcloc16.C: Likewise.
	* g++.dg/cpp2a/srcloc19.C: New test.
	* g++.dg/modules/adhoc-1_b.C: Adjust expected column numbers
	and caret line.
	* g++.dg/modules/macloc-1_c.C: Adjust expected column numbers.
	* g++.dg/modules/macloc-1_d.C: Likewise.
	* g++.dg/plugin/diagnostic-test-expressions-1.C: Adjust expected
	caret line.

	* testsuite/18_support/source_location/consteval.cc (main): Adjust
	expected column numbers.
	* testsuite/18_support/source_location/1.cc (main): Likewise.
2021-03-25 21:35:11 +01:00
..
1.cc c++: Fix source_location inconsistency between calls from templates and non-templates [PR99672] 2021-03-25 21:35:11 +01:00
consteval.cc c++: Fix source_location inconsistency between calls from templates and non-templates [PR99672] 2021-03-25 21:35:11 +01:00
srcloc.h Update copyright years. 2021-01-04 10:26:59 +01:00
version.cc Update copyright years. 2021-01-04 10:26:59 +01:00