public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: Diagnose this specifier on template parameters [PR113929]
Date: Fri, 16 Feb 2024 10:15:56 -0500	[thread overview]
Message-ID: <13b27d7b-70d3-489a-9670-739da09f324f@redhat.com> (raw)
In-Reply-To: <Zc8pMnDUZEXGVqep@tucnak>

On 2/16/24 04:21, Jakub Jelinek wrote:
> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 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.
> 
> --- gcc/cp/parser.cc.jj	2024-02-15 17:33:11.641453437 +0100
> +++ gcc/cp/parser.cc	2024-02-15 17:40:29.592447265 +0100
> @@ -25724,8 +25724,15 @@ cp_parser_parameter_declaration (cp_pars
>        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;
> +    }
>   
>     bool diag_xobj_parameter_pack = false;
>     if (xobj_param_p && (declarator && declarator->parameter_pack_p))
> --- gcc/testsuite/g++.dg/parse/pr113929.C.jj	2024-02-15 17:43:18.500129688 +0100
> +++ gcc/testsuite/g++.dg/parse/pr113929.C	2024-02-15 17:42:54.564458109 +0100
> @@ -0,0 +1,7 @@
> +// PR c++/113929
> +// { dg-do compile }
> +
> +template <this int C>		// { dg-error "'this' specifier in template parameter declaration" }
> +struct S {};
> +template <int N, this int C>	// { dg-error "'this' specifier in template parameter declaration" }
> +struct T {};
> 
> 	Jakub
> 


      reply	other threads:[~2024-02-16 15:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16  9:21 Jakub Jelinek
2024-02-16 15:15 ` Jason Merrill [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=13b27d7b-70d3-489a-9670-739da09f324f@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).