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.129.124]) by sourceware.org (Postfix) with ESMTPS id 576863858412 for ; Thu, 16 Dec 2021 16:00:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 576863858412 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-433-SeBr9oMNOs69QWVRNExMYA-1; Thu, 16 Dec 2021 11:00:19 -0500 X-MC-Unique: SeBr9oMNOs69QWVRNExMYA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A72D104 for ; Thu, 16 Dec 2021 16:00:18 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.18.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A39D6B8EC; Thu, 16 Dec 2021 16:00:18 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: delayed noexcept in member function template [PR99980] Date: Thu, 16 Dec 2021 11:00:14 -0500 Message-Id: <20211216160014.24338-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.2 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Dec 2021 16:00:22 -0000 Some time ago I noticed that we don't properly delay parsing of noexcept for member function templates. This patch fixes that. It didn't work because even though we set CP_PARSER_FLAGS_DELAY_NOEXCEPT in cp_parser_member_declaration, member template declarations take a different path: we call cp_parser_template_declaration and return prior to setting the flag. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/99980 gcc/cp/ChangeLog: * parser.c (cp_parser_single_declaration): Maybe pass CP_PARSER_FLAGS_DELAY_NOEXCEPT down to cp_parser_init_declarator. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept71.C: New test. --- gcc/cp/parser.c | 7 +++++- gcc/testsuite/g++.dg/cpp0x/noexcept71.C | 31 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept71.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c2564e51e41..c19e5f1359d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -31673,8 +31673,13 @@ cp_parser_single_declaration (cp_parser* parser, && (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON) || decl_specifiers.type != error_mark_node)) { + int flags = CP_PARSER_FLAGS_TYPENAME_OPTIONAL; + /* We don't delay parsing for friends, though CWG 2510 may change + that. */ + if (member_p && !(friend_p && *friend_p)) + flags |= CP_PARSER_FLAGS_DELAY_NOEXCEPT; decl = cp_parser_init_declarator (parser, - CP_PARSER_FLAGS_TYPENAME_OPTIONAL, + flags, &decl_specifiers, checks, /*function_definition_allowed_p=*/true, diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept71.C b/gcc/testsuite/g++.dg/cpp0x/noexcept71.C new file mode 100644 index 00000000000..361d6ad7b60 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept71.C @@ -0,0 +1,31 @@ +// PR c++/99980 +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert(X, #X) + +struct S { + template + void f(T) noexcept(B); + + struct N { + template + void f2(T) noexcept(B); + }; + + static constexpr bool B = true; +}; + +S s; +SA(noexcept(s.f(10))); +S::N n; +SA(noexcept(n.f2(10))); + +struct Bad { + template + using U = void() noexcept(B); // { dg-error "not declared" } + + template + friend void friendo() noexcept(B); // { dg-error "not declared" } + + static constexpr bool B = true; +}; base-commit: 41cc28405c74a5ec59c6725274aaedefa9ca5887 -- 2.33.1