aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/module.cc3
-rw-r--r--gcc/testsuite/g++.dg/modules/init-5_a.C9
-rw-r--r--gcc/testsuite/g++.dg/modules/init-5_b.C10
3 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index e0759a9..9bb6d264 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11707,7 +11707,8 @@ trees_out::write_var_def (tree decl)
{
tree dyn_init = NULL_TREE;
- if (DECL_NONTRIVIALLY_INITIALIZED_P (decl))
+ /* We only need to write initializers in header modules. */
+ if (header_module_p () && DECL_NONTRIVIALLY_INITIALIZED_P (decl))
{
dyn_init = value_member (decl,
CP_DECL_THREAD_LOCAL_P (decl)
diff --git a/gcc/testsuite/g++.dg/modules/init-5_a.C b/gcc/testsuite/g++.dg/modules/init-5_a.C
new file mode 100644
index 0000000..466b120
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/init-5_a.C
@@ -0,0 +1,9 @@
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi M }
+
+export module M;
+
+export struct A {
+ static int f() { return -1; }
+ static inline int x = f();
+};
diff --git a/gcc/testsuite/g++.dg/modules/init-5_b.C b/gcc/testsuite/g++.dg/modules/init-5_b.C
new file mode 100644
index 0000000..40973cc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/init-5_b.C
@@ -0,0 +1,10 @@
+// { dg-module-do run }
+// { dg-additional-options "-fmodules-ts" }
+
+import M;
+
+int main() {
+ const int& x = A::x;
+ if (x != -1)
+ __builtin_abort();
+}