From patchwork Thu May 2 05:19:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1930528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=A6JCHMso; 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 4VVMgf6rGlz1ymc for ; Thu, 2 May 2024 15:19:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A17F385842D for ; Thu, 2 May 2024 05:19:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 722903858D34 for ; Thu, 2 May 2024 05:19:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 722903858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 722903858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714627160; cv=none; b=t7w/qJua/N7+Bb74i7Vqq2LBrBV1u+tpNdaMsMCvvdTcRhK/lV9LCVxOdNkA0+65XVhRv2Q1Pisha18XPt4MTub7E2jaVnsWviulg8yjwho9FlkLvXCr4kYAEOLFXvMzUG7DZJeNcARgB9ncvBJTXSzLG/uoQzssLfbWOFAOyN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714627160; c=relaxed/simple; bh=hakRUX5dSIlK1T455OUmiEwT/i3Th64wa88YaaQuKVo=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=JsafO/DOutLWwQd4OE3xdz6l8nMYBvHkp7ealSxE+qbnBVYh8VM4ucUjhhUirKFYQnyAE0FQNnfDqtD8pJvuK7y4gRi3UcTtzpN02EmEbFiGkXX1AFNJ/ituUIiE4xrYiN3SqHxwdSv+9ijIti5ldrStmp5cUG0DN4DzrcnPxbU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6ed9fc77bbfso5978541b3a.1 for ; Wed, 01 May 2024 22:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714627157; x=1715231957; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Dw6n8INRwIw3akqjM4iec8585feP/4XorWbiwWZfJds=; b=A6JCHMsoRzJZOaoFzVhqjueMLUOfY1qdVC4TMsXDvApIIsBYkUm90ftcSYgpTfTwb0 JJx1/zTKaakvvB+6aMSfBCxps74GKzOS/eL0W+vU0qHa+DLLMLt7t+oYOYo3tIodqW9x /h0OmNwlUduIwjt/3Ad51jua6+PkYKFmSG6UDubMUQACHBc9ESbsAtM9mHraDwj//xn8 3LqLp+z67AMbdyOkmySz3mPD4UvaNY9ejXcbRb2nlWD9K6kTFhHH/He1B1feBqJEPerv RFsFl1i3shQM7Lg67Ts0FezT805gtVjzLJi/02jBriXe+ThhYGPC37LidL2ZBmW1III0 4oQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714627157; x=1715231957; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Dw6n8INRwIw3akqjM4iec8585feP/4XorWbiwWZfJds=; b=shoBzXGVpRuvR8cHrhE5fzd1pWwiosARzcU99l2xIWM8eviLW47bcuXdzPAbdGZ4A2 1IBK9yXcQXCjwm4dzBYsWXIal715HSfdeQF/a5sl58O5SmUjNglYpEGu+HAE72qUJe99 qaDVNd9EYyBMfkY9gFbaEmnIfEz2oVIPO4mKsQkDrcz0BL5NzTxbS5b6pNRDJn9Oa7zo 4mapPW64Nenhwmm06zvzK8GebJMKDEc2XsGEZCRinPkYfsiAaFqJ7FJ8WVS5VxlAmZjD o4svIFoQsyd49Wds1hsnpmHBlSkpPoaFI0VojR21DXWjPIKMZuLsk1T4SG9LAEGG4rAr YKjg== X-Gm-Message-State: AOJu0YzKa3G9AX0cIUYFDz0dMaY9iF1WQbqXHJQEd1VtzuGbe2AW2PC7 eccVUEdiMPJj/JOjWnk1uhVrXee1KvpGJgxP8YTzrK8oSj+o1fXu+T8xqA== X-Google-Smtp-Source: AGHT+IFjBquoQ9rN1sgx1vCnuKCxSun7Xs+CoC5Wm3OxRHTHMmOa7gJ2QUom4pK1BroHZoeFhO8/Ig== X-Received: by 2002:a05:6a20:2d22:b0:1af:4ed7:4059 with SMTP id g34-20020a056a202d2200b001af4ed74059mr1194133pzl.7.1714627157047; Wed, 01 May 2024 22:19:17 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id t26-20020a62ea1a000000b006ece7862035sm309950pfh.128.2024.05.01.22.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 22:19:16 -0700 (PDT) Message-ID: <66332254.620a0220.c0abb.0c82@mx.google.com> X-Google-Original-Message-ID: Date: Thu, 2 May 2024 15:19:11 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++: Clear is_unbraced_* when parsing declaration_seq_opt [PR114917] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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 Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- Currently we incorrectly retain "in_unbraced_linkage_specification_p" and "in_unbraced_export_declaration_p" when parsing a (braced) declaration-seq. This patch ensures that we clear these flags before parsing the toplevel declarations. Strictly speaking we don't need to save and restore the flags around the parsing because there's currently no way to provide new declarations within the unbraced context after the closing brace, but this patch does it anyway in case this ever changes and for consistency with other places where these flags are adjusted. PR c++/114917 gcc/cp/ChangeLog: * parser.cc (cp_parser_declaration_seq_opt): Clear parser->in_unbraced_* flags when parsing toplevel declarations. gcc/testsuite/ChangeLog: * g++.dg/modules/export-5_a.C: New test. * g++.dg/modules/export-5_b.C: New test. * g++.dg/parse/linkage4.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/parser.cc | 15 +++++++++++++++ gcc/testsuite/g++.dg/modules/export-5_a.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/modules/export-5_b.C | 13 +++++++++++++ gcc/testsuite/g++.dg/parse/linkage4.C | 11 +++++++++++ 4 files changed, 56 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/export-5_a.C create mode 100644 gcc/testsuite/g++.dg/modules/export-5_b.C create mode 100644 gcc/testsuite/g++.dg/parse/linkage4.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index a2bc6f69000..9a39ed27b23 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -15341,6 +15341,16 @@ cp_parser_module_export (cp_parser *parser) static void cp_parser_declaration_seq_opt (cp_parser* parser) { + bool saved_in_unbraced_linkage_specification_p + = parser->in_unbraced_linkage_specification_p; + bool saved_in_unbraced_export_declaration_p + = parser->in_unbraced_export_declaration_p; + + /* We're not in an unbraced linkage-specification + or export-declaration anymore. */ + parser->in_unbraced_linkage_specification_p = false; + parser->in_unbraced_export_declaration_p = false; + while (true) { cp_token *token = cp_lexer_peek_token (parser->lexer); @@ -15351,6 +15361,11 @@ cp_parser_declaration_seq_opt (cp_parser* parser) else cp_parser_toplevel_declaration (parser); } + + parser->in_unbraced_linkage_specification_p + = saved_in_unbraced_linkage_specification_p; + parser->in_unbraced_export_declaration_p + = saved_in_unbraced_export_declaration_p; } /* Parse a declaration. The distinction between name-declaration diff --git a/gcc/testsuite/g++.dg/modules/export-5_a.C b/gcc/testsuite/g++.dg/modules/export-5_a.C new file mode 100644 index 00000000000..a325591ca8e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/export-5_a.C @@ -0,0 +1,17 @@ +// PR c++/114917 +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi M } + +export module M; + +export namespace ns { + template struct S {}; + template struct S { using a = int; }; + template <> struct S { using b = int; }; + template struct S; +}; + +export extern "C++" namespace ns { + template void foo() {} + template <> void foo() {} +} diff --git a/gcc/testsuite/g++.dg/modules/export-5_b.C b/gcc/testsuite/g++.dg/modules/export-5_b.C new file mode 100644 index 00000000000..cb10e37c7fc --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/export-5_b.C @@ -0,0 +1,13 @@ +// PR c++/114917 +// { dg-additional-options "-fmodules-ts" } + +import M; + +int main() { + ns::S::a x{}; + ns::S::b y{}; + ns::S z{}; + + ns::foo(); + ns::foo(); +} diff --git a/gcc/testsuite/g++.dg/parse/linkage4.C b/gcc/testsuite/g++.dg/parse/linkage4.C new file mode 100644 index 00000000000..10fcc77e9d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/linkage4.C @@ -0,0 +1,11 @@ +// PR c++/114917 +// { dg-do compile } + +extern "C++" namespace ns { + struct Incomplete; + Incomplete foo; // { dg-error "incomplete type" } +} + +extern "C" extern "C" { + static int bar; // { dg-bogus "invalid" } +}