* [PATCH] c++/modules: Allow exporting const-qualified namespace-scope variables [PR99232]
@ 2023-11-15 12:24 Nathaniel Shead
2023-11-23 17:13 ` Nathan Sidwell
0 siblings, 1 reply; 2+ messages in thread
From: Nathaniel Shead @ 2023-11-15 12:24 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell
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 <nathanieloshead@gmail.com>
---
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);
--
2.42.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++/modules: Allow exporting const-qualified namespace-scope variables [PR99232]
2023-11-15 12:24 [PATCH] c++/modules: Allow exporting const-qualified namespace-scope variables [PR99232] Nathaniel Shead
@ 2023-11-23 17:13 ` Nathan Sidwell
0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2023-11-23 17:13 UTC (permalink / raw)
To: Nathaniel Shead, gcc-patches; +Cc: Jason Merrill
On 11/15/23 07:24, Nathaniel Shead wrote:
> 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).
ok, but can you augment the testcase to check the address is the same in both
TUs? (something like an accessor in the module and a runtime-check in the
importer?)
nathan
>
> 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 <nathanieloshead@gmail.com>
> ---
> 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);
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-23 17:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-15 12:24 [PATCH] c++/modules: Allow exporting const-qualified namespace-scope variables [PR99232] Nathaniel Shead
2023-11-23 17:13 ` Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).