From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2A3C53857C41 for ; Fri, 16 Feb 2024 15:16:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A3C53857C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2A3C53857C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708096563; cv=none; b=HutRH7fYOivK68FXOEviD7x/d5AN1mynzNFO1Envh2X4emASru59G04z4on2jRkR08LY9LY5+IrHdGgnQtCL4xa6CeAewnoW1xo3MxD9vY8SdSW8VAjLz9erPnOsH43pMqyyF8FvGqx71+dcWP8Mi6tJPXpOhbFB0RzYrQyiVZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708096563; c=relaxed/simple; bh=anSQGutD4qyotnR4OSxGrr0rEq9utmmhJZJi69vtjOQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=MUdeZFW0lwIm22pXs62Dyqvk+p3IMoKHpg4Pv6fGy6kvzWhst9CbOtwRTdoLFybDyMCwZGAQbZYuN+c2F3xW524ziLH5uIHNFOW3zLqnX58ja4fSiGfwCNhd7a/wIUTkTJyXUCT4opZwKiKFnCzMMbb/EQ+JtlBgbnk1hiqMjJE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708096560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bboCXZTHrfS1DpZIedlcfzQffcTl1MsuCpuudVZdXjI=; b=Bk8Oir8oG4Rrx+VAo2qY3H5aU+qXLVZQns/GCV/kdnCb7dsIn8nXTOumKpdOPwhdno1CyF 6mW7TTpTQH1S0GFnu9vFBklwSCgW9/RTjePpwnzHTYRSnrmdfoID2BeLewJlnIFaCQOaeM wSpDPcFfXkGdtPe3QDv7ziPOUSZVcwI= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-DqzB-T2SM5aZbe_J0OXmeA-1; Fri, 16 Feb 2024 10:15:59 -0500 X-MC-Unique: DqzB-T2SM5aZbe_J0OXmeA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7872a742a9bso199845185a.2 for ; Fri, 16 Feb 2024 07:15:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708096558; x=1708701358; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bboCXZTHrfS1DpZIedlcfzQffcTl1MsuCpuudVZdXjI=; b=LsJBPi4V9jW72lUynBA7PCns4sSPDzJkKOGPVelPEfiDN32gVZIjLL60BI3U0UIoSg +5bLWSxKJUBFbeticg2kUyCb4ou24v4qS/G+E1CSC5AN2//cbyyuo5KkPYjiO3urCXer eu+Ne2WrNKj6hhZb8cS9n3IJY2pIbcQ4K7AmIi0DN/qdXKYFuYJ1wvemfEU8kSsNFHf4 uNcmJqKXUVvlc9xCUUyOEuhbesE9mdpPl9yHVQDWWqqy8Wl77IbQFnax/TMtmpHHHLp9 Wbmqx7wJFBFvW7aTib/qBxHYzVsP9VVvqvEblBua3TaMmi1zD/CUr/RA8JJVsp5ag4W/ 07TA== X-Gm-Message-State: AOJu0Yw4QDfdPzq9BFJo57ioIFRf1Y3tS3Teob40+jK4VFkwq4akzEnO luk+TiMqQAWWeEbZPPqS/bU1tt/ZBwPiOMXDC+FmtPjMX5yR+WSQgOBGwkfVA2psQQTl/64yVsX /dmMpVWZtIILyQjG0aHvOS64tDMJgUE2abYmqUZO6FrbzId2ryZ5XoDA= X-Received: by 2002:a05:620a:2950:b0:783:6e92:e344 with SMTP id n16-20020a05620a295000b007836e92e344mr5900975qkp.62.1708096558550; Fri, 16 Feb 2024 07:15:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IELeA9A4MFofoAmBHIqPxie92NxhAy+W/dQOOb2tWK8/WBroYrzebRHFBx+GV1gZzHi25Bubg== X-Received: by 2002:a05:620a:2950:b0:783:6e92:e344 with SMTP id n16-20020a05620a295000b007836e92e344mr5900952qkp.62.1708096558260; Fri, 16 Feb 2024 07:15:58 -0800 (PST) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id i25-20020a05620a145900b00787407f2c7dsm26799qkl.100.2024.02.16.07.15.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Feb 2024 07:15:57 -0800 (PST) Message-ID: <13b27d7b-70d3-489a-9670-739da09f324f@redhat.com> Date: Fri, 16 Feb 2024 10:15:56 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: Diagnose this specifier on template parameters [PR113929] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 > > 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], > + "% 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 // { dg-error "'this' specifier in template parameter declaration" } > +struct S {}; > +template // { dg-error "'this' specifier in template parameter declaration" } > +struct T {}; > > Jakub >