From: Jason Merrill Date: Tue, 19 Nov 2024 20:59:40 +0000 (+0100) Subject: c++: inline variables and modules X-Git-Tag: basepoints/gcc-16~3981 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=819f67a2f633d2000f09119f0e19b784ea0a4bd8;p=thirdparty%2Fgcc.git c++: inline variables and modules We weren't writing out the definition of an inline variable, so the importer either got an undefined symbol or 0. gcc/cp/ChangeLog: * module.cc (has_definition): Also true for inline vars. gcc/testsuite/ChangeLog: * g++.dg/modules/inline-1_a.C: New test. * g++.dg/modules/inline-1_b.C: New test. --- diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 3b25f9569280..617bf4c68b18 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11919,7 +11919,8 @@ has_definition (tree decl) since there's no TU to emit them in otherwise. */ return true; - if (!decl_maybe_constant_var_p (decl)) + if (!decl_maybe_constant_var_p (decl) + && !DECL_INLINE_VAR_P (decl)) return false; return true; diff --git a/gcc/testsuite/g++.dg/modules/inline-1_a.C b/gcc/testsuite/g++.dg/modules/inline-1_a.C new file mode 100644 index 000000000000..eafd450e6677 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/inline-1_a.C @@ -0,0 +1,11 @@ +// { dg-additional-options -fmodules } +// { dg-module-do run } +export module M; + +inline int b = 42; +struct A +{ + static inline int a = 4200; +}; + +export inline int f() { return b+A::a; } diff --git a/gcc/testsuite/g++.dg/modules/inline-1_b.C b/gcc/testsuite/g++.dg/modules/inline-1_b.C new file mode 100644 index 000000000000..af319b160710 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/inline-1_b.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules } +import M; + +int main() +{ + if (f() != 4242) + __builtin_abort (); +}