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: 1895489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Skx9/VZw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TTSww6lB4z23gb for ; Tue, 6 Feb 2024 14:12:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ECAAB385843B for ; Tue, 6 Feb 2024 03:12:46 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 } } +};