From patchwork Tue Feb 6 03:12:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 197154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1293090dyb; Mon, 5 Feb 2024 19:13:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHP0UpiDqjprsPmFnkLHry6XovpXlC69IQEE7K3i0nT8BHgykH+ESLCDC2fyOG3+kGxTFQj X-Received: by 2002:a05:620a:5612:b0:785:752e:8584 with SMTP id vu18-20020a05620a561200b00785752e8584mr1296740qkn.1.1707189189071; Mon, 05 Feb 2024 19:13:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707189189; cv=pass; d=google.com; s=arc-20160816; b=WLm6NiK1QZfqLmrIaCoTQp0dJhuC6OocwMUxdoH/7g7Mye0+Enzr8GJwinXX+e21iu KYWDkZRt5OuFHD5ufmm3tUGRbnMvrpPxwMK+TunDoVp7DPVWl6xaosHJUVT8vud3CWQs fZeIAizulp/MqwM+G8smG56H1QBHCz3yrb8eJJYmft7NA1CP0d20J4UijnpcHZM78ecP B9wH0MSFwdH3pdGAnNdgPQc20WrGRz71M/JufkNrM++44txDictp/5Smf7JVEkQGjaVQ JmTxcL3IvANHXeGB3WI3Tt2JFVuwM5HGJplC4pDohe7UznNi7ZCZWHGg8NdAwig1Uufj irOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=X1oSESXmg3J8ydw5nYjgr9htUrMj0k1j9evDrfoAkU8=; fh=08rkNykk9tugU9034lv1/RNOp/MN3Y78I3CUaKQOYHs=; b=l1llNGf2d6yjQFTK30eascGiaps2WDEe6Pff+fUyQ3qOuBNctQQIhDpEk6kVGSt97P FdnipUuCFN+RgZ85Q/zazymyrICAfB5ySjkdmAhxbZXIf8D9Hg9NEbsW/eknmIE68/me nROB2hYwBSonUN9/Tc8qEPh3S84w0TybVppK55XM8EWQHCQhZb457Ov6UvuqAH4PdH7J iEFiJS0hEpDj/2G7som2XCVgYon/8FJEUbh3cjNOxCPOXDRRtkn3QAjx8BbwiFvPxoew qEbQa0Db8boOoNqubD2daCDf6g8mf19Otb3Dvuo6ZmDTFN+ZhVP2mQNT81Mx7y/oYKGq 2eDg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Skx9/VZw"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCU4GBltTVQI+5vw1plqeYqH6WFko5ZBzvSY0ZufL6MP/OyzwuCnpn4E9pQIaWYJwY1qsKlx6/lSuIorCNc6cYfhYV6ZOQ== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d24-20020a05620a159800b00783fc517e95si1394452qkk.413.2024.02.05.19.13.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 19:13:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Skx9/VZw"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C20753858C42 for ; Tue, 6 Feb 2024 03:13:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 648B23858416 for ; Tue, 6 Feb 2024 03:12:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 648B23858416 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 648B23858416 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=1707189148; cv=none; b=roNiZxsp6Stc4UK/U45HeBH3QAEI/hG6xNFLBqLXs+P1eEpijjouiY0PInun0S5tNlq6aVtb7YhdYOvEhvK4j42GEpPA2vdCGMIMCMBtcqWmA5GPtCezvLTe8NKcRFeIgjq0kUf7iH08pMhdTnMwaMVwBHI/vQa7TNReD7MK6q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707189148; c=relaxed/simple; bh=fEPoeFN03V9bhDS+/juQYf7pCaQNU8ujL6Ltf0tdp6g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=G3ynAOaVMOmOXLCEdBaSVchwqiUUR0fwZjjhNBLMmMISupOMUVyjynzv0Y8+kZ0Tdaj+J7WKetiX/6Y+CgWd3os1jRFVwF/AuKgfk+VfIPATAL/2HTy+/7APhHmPMu4itGu/4w9JE705A8bXXdDLoGPXy9fp8S/bnmFRiFq6Asg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707189146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=X1oSESXmg3J8ydw5nYjgr9htUrMj0k1j9evDrfoAkU8=; b=Skx9/VZwIWVJqBiYOilVKD/O4YDG8LzPXxBQStVGRwBrp1bmou7Da2J/egOZO+EoHeqgCX qUY7OG7g5UQ/lWPaUFc1OLpOCL0Ogt823jbWom57mH6XP7FUbWjgemDsIW9CUOMmPIj7m4 JFBl1f4whAEHZyx4dNh19H4wK8McnsI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-vQ4gsKTsPJSz5rnXz08zfA-1; Mon, 05 Feb 2024 22:12:24 -0500 X-MC-Unique: vQ4gsKTsPJSz5rnXz08zfA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8516F1C0650C for ; Tue, 6 Feb 2024 03:12:24 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.16.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id 674153C2E; Tue, 6 Feb 2024 03:12:24 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: further DR 2237 fix [PR97202] Date: Mon, 5 Feb 2024 22:12:15 -0500 Message-ID: <20240206031215.1301256-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790117611118258371 X-GMAIL-MSGID: 1790117611118258371 Technically, not a regression. But it's such a simple fix for such rare code that I think we should put it in now and be done with DR 2237. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- With a redundant inline specifier like this: template struct S : Base { inline S() {} }; we don't detect the simple-template-id as the declarator-id of the constructor. The problem is that I check for CPP_TEMPLATE_ID too early, at a point at which cp_parser_template_id may not have been called yet. So let's check for it at the end of the function, after the tentative parse and rollback. PR c++/97202 gcc/cp/ChangeLog: * parser.cc (cp_parser_constructor_declarator_p): Check CPP_TEMPLATE_ID at the end of the function. gcc/testsuite/ChangeLog: * g++.dg/DRs/dr2237-5.C: New test. --- gcc/cp/parser.cc | 4 +--- gcc/testsuite/g++.dg/DRs/dr2237-5.C | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/DRs/dr2237-5.C base-commit: c5d34912ad576be1ef19be92f7eabde54b9089eb prerequisite-patch-id: 2987a013eda8bc2ca9d8373eedac82067a654a5c diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 473eaf4f1f7..8befd26feab 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -32337,8 +32337,6 @@ cp_parser_constructor_declarator_p (cp_parser *parser, cp_parser_flags flags, && next_token->type != CPP_TEMPLATE_ID) return false; - const bool saw_template_id = (next_token->type == CPP_TEMPLATE_ID); - /* Parse tentatively; we are going to roll back all of the tokens consumed here. */ cp_parser_parse_tentatively (parser); @@ -32558,7 +32556,7 @@ cp_parser_constructor_declarator_p (cp_parser *parser, cp_parser_flags flags, /* DR 2237 (C++20 only): A simple-template-id is no longer valid as the declarator-id of a constructor or destructor. */ if (constructor_p - && saw_template_id + && cp_lexer_peek_token (parser->lexer)->type == CPP_TEMPLATE_ID && !cp_parser_uncommitted_to_tentative_parse_p (parser)) { auto_diagnostic_group d; diff --git a/gcc/testsuite/g++.dg/DRs/dr2237-5.C b/gcc/testsuite/g++.dg/DRs/dr2237-5.C new file mode 100644 index 00000000000..fd51968f7e1 --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr2237-5.C @@ -0,0 +1,7 @@ +// PR c++/97202 +// { dg-options "" } + +template struct S : Base { + inline S() {} // { dg-warning "template-id not allowed for constructor" "" { target c++20 } } + inline ~S() {} // { dg-warning "template-id not allowed for destructor" "" { target c++20 } } +};