]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix source_location inconsistency between calls from templates and non-templates...
authorJakub Jelinek <jakub@redhat.com>
Thu, 25 Mar 2021 20:35:11 +0000 (21:35 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 25 Mar 2021 20:35:11 +0000 (21:35 +0100)
commit2132a36370e282d8c0ed0c97e5bfb952e23dbfa1
tree2c32fe9fece7879355c5dc04d03392db4aaed74c
parentd4e0bdbc036644401f9de49f594b2bb16b287381
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.
14 files changed:
gcc/cp/parser.c
gcc/testsuite/g++.dg/concepts/diagnostic2.C
gcc/testsuite/g++.dg/cpp1y/builtin_location.C
gcc/testsuite/g++.dg/cpp2a/srcloc1.C
gcc/testsuite/g++.dg/cpp2a/srcloc15.C
gcc/testsuite/g++.dg/cpp2a/srcloc16.C
gcc/testsuite/g++.dg/cpp2a/srcloc19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/srcloc2.C
gcc/testsuite/g++.dg/modules/adhoc-1_b.C
gcc/testsuite/g++.dg/modules/macloc-1_c.C
gcc/testsuite/g++.dg/modules/macloc-1_d.C
gcc/testsuite/g++.dg/plugin/diagnostic-test-expressions-1.C
libstdc++-v3/testsuite/18_support/source_location/1.cc
libstdc++-v3/testsuite/18_support/source_location/consteval.cc