From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id A14423857B92; Fri, 16 Feb 2024 16:43:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A14423857B92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708101822; bh=6liJukFmRCrRwiX4D3pkITwkLAnAHvT2ez0cqzbaHVo=; h=From:To:Subject:Date:From; b=y7CYDWLO2dYpDa/xOfKBQlOwq0gEBgYvpE7JyOSnDoTJrgqXvlGgcg/vqCdGBCgvE ijIsfUe0jLIHEV3nh0V8Hedmjx4BxNSv9IIT1SrtsOpnVIwHisoPCJpFTOn3b8IJ+P suABzgPpzIyDF5NkKCNuSHUJ4YhUSN/PMy3vNN3g= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9033] c++: Diagnose this specifier on template parameters [PR113929] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 945cb8490cbdb558e010878f2fb70f5ef088d7ec X-Git-Newrev: 5286b0761b5dfac4348d1c5bfdcc162a66f338ee Message-Id: <20240216164342.A14423857B92@sourceware.org> Date: Fri, 16 Feb 2024 16:43:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5286b0761b5dfac4348d1c5bfdcc162a66f338ee commit r14-9033-g5286b0761b5dfac4348d1c5bfdcc162a66f338ee Author: Jakub Jelinek Date: Fri Feb 16 17:42:32 2024 +0100 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 PR c++/113929 * parser.cc (cp_parser_parameter_declaration): Diagnose this specifier on template parameter declaration. * g++.dg/parse/pr113929.C: New test. Diff: --- gcc/cp/parser.cc | 9 ++++++++- gcc/testsuite/g++.dg/parse/pr113929.C | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 9d0914435fb1..b2ed2baa3a57 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], + "% specifier in template parameter declaration"); + xobj_param_p = false; + decl_specifiers.locations[ds_this] = 0; + } if (xobj_param_p && ((declarator && declarator->parameter_pack_p) diff --git a/gcc/testsuite/g++.dg/parse/pr113929.C b/gcc/testsuite/g++.dg/parse/pr113929.C new file mode 100644 index 000000000000..4410f7bf85a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/pr113929.C @@ -0,0 +1,7 @@ +// PR c++/113929 +// { dg-do compile } + +template // { dg-error "'this' specifier in template parameter declaration" } +struct S {}; +template // { dg-error "'this' specifier in template parameter declaration" } +struct T {};