aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-02-16 17:42:32 +0100
committerJakub Jelinek <jakub@redhat.com>2024-02-16 17:42:32 +0100
commit5286b0761b5dfac4348d1c5bfdcc162a66f338ee (patch)
treea6f84a3e6b61a8113bfacd68cd191e66242411aa /gcc/cp/parser.cc
parent945cb8490cbdb558e010878f2fb70f5ef088d7ec (diff)
downloadgcc-5286b0761b5dfac4348d1c5bfdcc162a66f338ee.zip
gcc-5286b0761b5dfac4348d1c5bfdcc162a66f338ee.tar.gz
gcc-5286b0761b5dfac4348d1c5bfdcc162a66f338ee.tar.bz2
c++: Diagnose this specifier on template parameters [PR113929]
For template parameters, the optional this specifier is in the grammar template-parameter-list -> template-parameter -> parameter-declaration, just [dcl.fct/6] says that it is only valid in parameter-list of certain functions. So, unlike the case of decl-specifier-seq used in non-terminals other than parameter-declaration, I think it is better not to fix this by cp_parser_decl_specifier_seq (parser, - flags | CP_PARSER_FLAGS_PARAMETER, + flags | (template_parameter_p ? 0 + : CP_PARSER_FLAGS_PARAMETER), &decl_specifiers, &declares_class_or_enum); which would be pretending it isn't in the grammar, but by diagnosing it separately, which is what the following patch does. 2024-02-16 Jakub Jelinek <jakub@redhat.com> PR c++/113929 * parser.cc (cp_parser_parameter_declaration): Diagnose this specifier on template parameter declaration. * g++.dg/parse/pr113929.C: New test.
Diffstat (limited to 'gcc/cp/parser.cc')
-rw-r--r--gcc/cp/parser.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 9d09144..b2ed2ba 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -25724,8 +25724,15 @@ cp_parser_parameter_declaration (cp_parser *parser,
for a C-style variadic function. */
token = cp_lexer_peek_token (parser->lexer);
- bool const xobj_param_p
+ bool xobj_param_p
= decl_spec_seq_has_spec_p (&decl_specifiers, ds_this);
+ if (xobj_param_p && template_parm_p)
+ {
+ error_at (decl_specifiers.locations[ds_this],
+ "%<this%> specifier in template parameter declaration");
+ xobj_param_p = false;
+ decl_specifiers.locations[ds_this] = 0;
+ }
if (xobj_param_p
&& ((declarator && declarator->parameter_pack_p)