]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Disallow this specifier except for parameter declarations [PR113788]
authorJakub Jelinek <jakub@redhat.com>
Tue, 6 Feb 2024 21:34:55 +0000 (22:34 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 6 Feb 2024 21:34:55 +0000 (22:34 +0100)
commit40485378ade83102d7aa30c317f5d6c90c1d232b
tree659241acfaab490b5a81ca5a3972ceb5466dfcf9
parentf2a060820c24724bb48ee006d257c449e4d94b72
c++: Disallow this specifier except for parameter declarations [PR113788]

The deducing this patchset added parsing of this specifier to
cp_parser_decl_specifier_seq unconditionally, but in the C++ grammar
this[opt] only appears in the parameter-declaration non-terminal, so
rather than checking in all the callers of cp_parser_decl_specifier_seq
except for cp_parser_parameter_declaration that this specifier didn't
appear I think it is far easier and closer to what the standard says
to only parse this specifier when called from
cp_parser_parameter_declaration.

2024-02-06  Jakub Jelinek  <jakub@redhat.com>

PR c++/113788
* parser.cc (CP_PARSER_FLAGS_PARAMETER): New enumerator.
(cp_parser_decl_specifier_seq): Parse RID_THIS only if
CP_PARSER_FLAGS_PARAMETER is set in flags.
(cp_parser_parameter_declaration): Or in CP_PARSER_FLAGS_PARAMETER
when calling cp_parser_decl_specifier_seq.

* g++.dg/parse/pr113788.C: New test.
gcc/cp/parser.cc
gcc/testsuite/g++.dg/parse/pr113788.C [new file with mode: 0644]