From patchwork Wed Nov 15 12:24:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1864227 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=lv85/T8y; 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 4SVj6Q4XjWz1yRV for ; Wed, 15 Nov 2023 23:25:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF3873858412 for ; Wed, 15 Nov 2023 12:24:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 1390A3858D20 for ; Wed, 15 Nov 2023 12:24:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1390A3858D20 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 1390A3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700051089; cv=none; b=XJN/t1lPgxDxrDo1sLdj3U0bap1BMqPkT2dJ0NTiZQb0h31TNTG2VtW2pRUrlrZVVBFe+BUkYsWV3skfOXlE4GXjb6kqu7fTeyM3wob5CCMcnTOLPGxA2z3Jd4SLJHyA5ak7LLPhlIY45wq6wHNj9AJBChisOWgkXf2L6oD/k+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700051089; c=relaxed/simple; bh=vmEo3iirZip4lcIkcJ9Tr8peXZr0XBmgabh9LCCgisA=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=wRZiQdRH9T9/2gwf2uXqmpbazvOuUeuy7C5jvDCr1hXjjGjpJ7k22EPouqgwbGK23jpxP70wLgSP4Dxd59heGyepnCt8Qq0H4/S3tQUiCRCHu86YnMb/CapQ1hwXb+pablq/kaUQM3smBCYR4vEPfiSA9LV/dLWTeRojvrEm4WI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6bd73395bceso637308b3a.0 for ; Wed, 15 Nov 2023 04:24:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700051086; x=1700655886; 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=AcBomnseNgssx1atxSB8YT5TAupZ5HnDCVLvSspHU48=; b=lv85/T8yn0FButLxWLgWy5phUHrkif8P20+3OKe3QlSGapseNGDAbgHqtJuitdPp8v UgPDol0Uztn8zeiwgr89GUR2onKFMcERS6h+3sJ7EWOPA41In9B2gl+kTIYrTgAWQS7V 3LuE8NEHD8WHeNJ5GHEn5fei7MiSgCSXvHwibKpK561lqGOb6MRUynmGGwbGlF8lO45I +E1ty7V3XVXAs/X00+uKlvf7GRTGqzjARoNtx+hVdc7hbsXAEOU3P+KolmFw7sxm0wRs i2Zw6O3AHfgEptzk1X5h2s2hN2gevRYtkH+20IEK5UPzX6zGlN3A6kX4+eR+iMEuh26x v4OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700051086; x=1700655886; 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=AcBomnseNgssx1atxSB8YT5TAupZ5HnDCVLvSspHU48=; b=qJsuqq1Wew0WMh2DJqo9Vq9j56mdrXSDyh257lLpSeG/p56sFAAu0h+NdEHVI868/e QjdBAdvandyrfPzdR4+6ejYYdNKS6cs8nF9lIh4EogmhBkEObnTwSkejWBoE+nSwGMqy ZfbTvZkzUTL2H+WUd1z0UFc5kxNUa/nNc5LpSJqxWAYzznG07YuVquQ+F8PJdFEP4Sj6 cqYQANbDe4Y1EL4qm0C2Bvq5mWRjVzaWD0d1d3UTJZRWYMEw2dipRGMJO2Kr+RwBZRF3 eO7jqzMGnhlaAFa6ABihKAVdfbhEONp9Q09R2cyTKh+wufir8JyJ0Xc4O/9YD5iBdXD+ V9sA== X-Gm-Message-State: AOJu0Yz+D7pgskJC0OQuaQbLpDZ13o8Zo0kiG9Atm//VLeIoTmBfmsfK C5jZEzj1+0EqQlG3+HUVAh1NpuytQ4s= X-Google-Smtp-Source: AGHT+IG1qqxUYk2DZ60tmVPugl+cWyKEKT+s8cNTCkv1lqGDnEh5xyfNRNKy2/Ktbj5lG21X0xlorA== X-Received: by 2002:a05:6a20:1601:b0:187:449d:a4cd with SMTP id l1-20020a056a20160100b00187449da4cdmr4156294pzj.27.1700051086436; Wed, 15 Nov 2023 04:24:46 -0800 (PST) Received: from Thaum. (124-150-88-161.tpgi.com.au. [124.150.88.161]) by smtp.gmail.com with ESMTPSA id k17-20020aa792d1000000b006bc3e8f58besm2742612pfa.56.2023.11.15.04.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 04:24:45 -0800 (PST) Message-ID: <6554b88d.a70a0220.35c73.8474@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 15 Nov 2023 23:24:40 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: Allow exporting const-qualified namespace-scope variables [PR99232] 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, 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 Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write access. -- >8 -- By [basic.link] p3.2.1, a non-template non-volatile const-qualified variable is not necessarily internal linkage in a module declaration, and rather may have module linkage (or external linkage if it is exported, see p4.8). PR c++/99232 gcc/cp/ChangeLog: * decl.cc (grokvardecl): Don't mark variables attached to modules as internal. gcc/testsuite/ChangeLog: * g++.dg/modules/pr99232_a.C: New test. * g++.dg/modules/pr99232_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/decl.cc | 3 ++- gcc/testsuite/g++.dg/modules/pr99232_a.C | 8 ++++++++ gcc/testsuite/g++.dg/modules/pr99232_b.C | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr99232_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr99232_b.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index d2ed46b1453..173dd93ef5b 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -10992,7 +10992,8 @@ grokvardecl (tree type, && (DECL_THIS_EXTERN (decl) || ! constp || volatilep - || inlinep)); + || inlinep + || module_attach_p ())); TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); } /* Not at top level, only `static' makes a static definition. */ diff --git a/gcc/testsuite/g++.dg/modules/pr99232_a.C b/gcc/testsuite/g++.dg/modules/pr99232_a.C new file mode 100644 index 00000000000..33b3b783399 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99232_a.C @@ -0,0 +1,8 @@ +// PR c++/99232 +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi pr99232 } + +export module pr99232; + +export const double lambda{ 1.3 }; +export constexpr int a = 42; diff --git a/gcc/testsuite/g++.dg/modules/pr99232_b.C b/gcc/testsuite/g++.dg/modules/pr99232_b.C new file mode 100644 index 00000000000..98f3c52a51c --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99232_b.C @@ -0,0 +1,7 @@ +// PR c++/99232 +// { dg-additional-options "-fmodules-ts" } + +import pr99232; + +double foo() { return lambda * 2.0; } +static_assert(a == 42);