diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index d19d09adde43b713b6c4149f0c3c4ed901f9d3d1..e47f694e4e566cafaf69b98d019a40513e724f8e 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -7954,6 +7954,10 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec) && DECL_IMPLICIT_INSTANTIATION (decl)) defer_p = 1; + /* Defer vague-linkage variables. */ + if (DECL_INLINE_VAR_P (decl)) + defer_p = 1; + /* If we're not deferring, go ahead and assemble the variable. */ if (!defer_p) rest_of_decl_compilation (decl, toplev, at_eof); diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index f569d4045ecca4c1f9008068fdd56f7032588c45..1dddbaab38b06af9ebd25a844fcd7b7d5fd9b3f4 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -3360,7 +3360,9 @@ import_export_decl (tree decl) * implicit instantiations of function templates - * inline function + * inline functions + + * inline variables * implicit instantiations of static data members of class templates @@ -3383,6 +3385,7 @@ import_export_decl (tree decl) || DECL_DECLARED_INLINE_P (decl)); else gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl) + || DECL_INLINE_VAR_P (decl) || DECL_VTABLE_OR_VTT_P (decl) || DECL_TINFO_P (decl)); /* Check that a definition of DECL is available in this translation @@ -3511,7 +3514,7 @@ import_export_decl (tree decl) this entity as undefined in this translation unit. */ import_p = true; } - else if (DECL_FUNCTION_MEMBER_P (decl)) + else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (decl)) { if (!DECL_DECLARED_INLINE_P (decl)) { diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-1.C index 85f74a91521f2ed1ba0637eea17ebfc92439b43b..7ec20afc065c63ebb002567db3e1fa7cccf4b3c4 100644 --- a/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-1.C +++ b/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-1.C @@ -8,6 +8,8 @@ // { dg-final { scan-assembler-times " DW_AT_\[^\n\r]*linkage_name" 7 } } inline int a; +int& ar = a; + struct S { static inline double b = 4.0; diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-3.C b/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-3.C index 6345b5e2ec8462056851ee15325ab88095fe6200..bb40a2295512f3e4485b11fb45553029b328d2ff 100644 --- a/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-3.C +++ b/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-3.C @@ -11,6 +11,8 @@ // { dg-final { scan-assembler-times " DW_AT_\[^\n\r]*linkage_name" 7 } } inline int a; +int& ar = a; + struct S { static inline double b = 4.0; diff --git a/gcc/testsuite/g++.dg/modules/init-7_a.H b/gcc/testsuite/g++.dg/modules/init-7_a.H new file mode 100644 index 0000000000000000000000000000000000000000..7a0bb721c307662a2c52d420ecea1ebc86e1dfa0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-7_a.H @@ -0,0 +1,6 @@ +// PR c++/113708 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +inline int f() { return 42; } +inline int a = f(); diff --git a/gcc/testsuite/g++.dg/modules/init-7_b.C b/gcc/testsuite/g++.dg/modules/init-7_b.C new file mode 100644 index 0000000000000000000000000000000000000000..58bb0620ca513560d4c212bedd8ff880e230fcd3 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-7_b.C @@ -0,0 +1,6 @@ +// PR c++/113708 +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts" } + +import "init-7_a.H"; +int main() { a; }