@@ -11809,6 +11809,7 @@ trees_in::read_var_def (tree decl, tree maybe_template)
{
if (DECL_EXTERNAL (decl))
DECL_NOT_REALLY_EXTERN (decl) = true;
+ DECL_INITIAL (decl) = init;
if (VAR_P (decl))
{
DECL_INITIALIZED_P (decl) = true;
@@ -11819,8 +11820,17 @@ trees_in::read_var_def (tree decl, tree maybe_template)
&& !DECL_VTABLE_OR_VTT_P (decl)
&& !DECL_TEMPLATE_INFO (decl)))
note_vague_linkage_variable (decl);
+
+ /* Emit RTL as needed, as with make_rtl_for_nonlocal_decl. */
+ // FIXME: Handle asmspec?
+ if ((!DECL_FUNCTION_SCOPE_P (decl)
+ || (TREE_STATIC (decl) && var_in_maybe_constexpr_fn (decl)))
+ && !DECL_VIRTUAL_P (decl)
+ && (!DECL_TEMPLATE_INFO (decl)
+ || DECL_EXPLICIT_INSTANTIATION (decl)))
+ rest_of_decl_compilation (decl, !DECL_FUNCTION_SCOPE_P (decl),
+ /*at_end=*/0);
}
- DECL_INITIAL (decl) = init;
if (!dyn_init)
;
else if (CP_DECL_THREAD_LOCAL_P (decl))
new file mode 100644
@@ -0,0 +1,6 @@
+// PR c++/113708
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+inline int f() { return 42; }
+inline int a = f();
new file mode 100644
@@ -0,0 +1,6 @@
+// PR c++/113708
+// { dg-module-do link }
+// { dg-additional-options "-fmodules-ts" }
+
+import "init-7_a.H";
+int main() { a; }
Bootstrapped and regtested (just modules.exp so far) on x86_64-pc-linux-gnu, OK for trunk if full regtest succeeds? -- >8 -- Currently inline vars imported from modules aren't correctly finalised, which means that import_export_decl gets called at the end of TU processing despite not being meant to for these kinds of declarations. This patch takes the logic from 'make_rtl_for_nonlocal_decl' to determine when to perform rest of decl compilation on these decls. However other parts of this function (asmspec handling) are not yet covered. PR c++/113708 gcc/cp/ChangeLog: * module.cc (trees_in::read_var_def): Perform rest of decl compilation on non-local statics. gcc/testsuite/ChangeLog: * g++.dg/modules/init-7_a.H: New test. * g++.dg/modules/init-7_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> --- gcc/cp/module.cc | 12 +++++++++++- gcc/testsuite/g++.dg/modules/init-7_a.H | 6 ++++++ gcc/testsuite/g++.dg/modules/init-7_b.C | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/init-7_a.H create mode 100644 gcc/testsuite/g++.dg/modules/init-7_b.C