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.
This commit is contained in:
Jason Merrill 2024-11-19 21:59:40 +01:00
parent 74498be0e6
commit 819f67a2f6
3 changed files with 21 additions and 1 deletions

View File

@ -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;

View File

@ -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; }

View File

@ -0,0 +1,8 @@
// { dg-additional-options -fmodules }
import M;
int main()
{
if (f() != 4242)
__builtin_abort ();
}