diff options
author | Marek Polacek <polacek@redhat.com> | 2023-11-09 12:25:25 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2023-11-15 22:22:20 -0500 |
commit | 70060dadfbf0d0af5f4cab5f3aff3223a4523606 (patch) | |
tree | 8197907f6b80bf58e65078ab6be19c76ffe7ce7d /gcc/gcov-tool.cc | |
parent | 9251db0dabc8e75c31b49a5b589124e9a2bc8299 (diff) | |
download | gcc-70060dadfbf0d0af5f4cab5f3aff3223a4523606.zip gcc-70060dadfbf0d0af5f4cab5f3aff3223a4523606.tar.gz gcc-70060dadfbf0d0af5f4cab5f3aff3223a4523606.tar.bz2 |
c++: fix parsing with auto(x) [PR112410]
Here we are wrongly parsing
int y(auto(42));
which uses the C++23 cast-to-prvalue feature, and initializes y to 42.
However, we were treating the auto as an implicit template parameter.
Fixing the auto{42} case is easy, but when auto is followed by a (,
I found the fix to be much more involved. For instance, we cannot
use cp_parser_expression, because that can give hard errors. It's
also necessary to disambiguate 'auto(i)' as 'auto i', not a cast.
auto(), auto(int), auto(f)(int), auto(*), auto(i[]), auto(...), etc.
are all function declarations.
This patch rectifies that by undoing the implicit function template
modification. In the test above, we should notice that the parameter
list is ill-formed, and since we've synthesized an implicit template
parameter, we undo it by calling abort_fully_implicit_template. Then,
we'll parse the "(auto(42))" as an initializer.
PR c++/112410
gcc/cp/ChangeLog:
* parser.cc (cp_parser_direct_declarator): Maybe call
abort_fully_implicit_template if it turned out the parameter list was
ill-formed.
gcc/testsuite/ChangeLog:
* g++.dg/cpp23/auto-fncast13.C: New test.
* g++.dg/cpp23/auto-fncast14.C: New test.
Diffstat (limited to 'gcc/gcov-tool.cc')
0 files changed, 0 insertions, 0 deletions