From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7948) id 9E6CB3858D32; Fri, 24 Nov 2023 13:55:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E6CB3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700834143; bh=sE2kZLqzjZtnERwu9UO5igfxmsrZK0WMy20pTVaGX3g=; h=From:To:Subject:Date:From; b=aDPPRCnrNgo5YkfFxWcY2jkg2CQ45TqUyNFsaMMfWeSeJTqnJR1Nt+1m2aQE/QJUJ WH92StbA207wKONI5xyQN/OAwJuaZ5DpIResSDXGRVl4uoO+Xsj2v0fXJUchSDLOhU nPRdroeX4ZAoLB1p0ZUNcuDxie5lM0QIbuql5Vt8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Nathaniel Shead To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-5826] c++: Allow exporting const-qualified namespace-scope variables [PR99232] X-Act-Checkin: gcc X-Git-Author: Nathaniel Shead X-Git-Refname: refs/heads/master X-Git-Oldrev: aea337cf740ec33022f3cabfa7dd4333d5ba78ee X-Git-Newrev: 726723c476800285cfbdfce612cedde4a9a7ad58 Message-Id: <20231124135543.9E6CB3858D32@sourceware.org> Date: Fri, 24 Nov 2023 13:55:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:726723c476800285cfbdfce612cedde4a9a7ad58 commit r14-5826-g726723c476800285cfbdfce612cedde4a9a7ad58 Author: Nathaniel Shead Date: Wed Nov 15 20:50:53 2023 +1100 c++: Allow exporting const-qualified namespace-scope variables [PR99232] 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 Diff: --- gcc/cp/decl.cc | 3 ++- gcc/testsuite/g++.dg/modules/pr99232_a.C | 12 ++++++++++++ gcc/testsuite/g++.dg/modules/pr99232_b.C | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 16b04ebe0f8..ed1401591fa 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -11006,7 +11006,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..097fb5e4403 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99232_a.C @@ -0,0 +1,12 @@ +// 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; + +export const double* get_lambda_addr() { + return λ +} 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..a36a76fa5b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99232_b.C @@ -0,0 +1,13 @@ +// PR c++/99232 +// { dg-module-do run } +// { dg-additional-options "-fmodules-ts" } + +import pr99232; + +double foo() { return lambda * 2.0; } +static_assert(a == 42); + +int main() { + if (&lambda != get_lambda_addr()) + __builtin_abort(); +}