Debian Codegraph @

gcc/testsuite/g++.dg/modules/internal-11.C

raw
1 // PR c++/119551
2 // { dg-additional-options "-fmodules" }
3 // { dg-module-cmi !M }
4
5 export module M;
6
7 static int tu_local = 5;
8 static int* foo() { return &tu_local; }
9
10 // For implementation reasons, we adjust [basic.link] p14.2 to restrict ignored
11 // exposures to non-inline variables, since for inline variables without
12 // dynamic initialisation we need to emit their initialiser for importer use.
13
14 int* a = &tu_local; // OK
15 inline int* b = &tu_local; // { dg-error "exposes TU-local entity" }
16
17 // But dynamic initialisers are fine, importers will just treat them as external.
18 inline int* c = foo(); // OK
19
20 // For consistency, we follow the same rules with templates, noting that
21 // we still need to emit definitions with dynamic initializers so we error.
22 template <typename T> int* d = &tu_local; // OK
23 template <typename T> inline int* e = &tu_local; // { dg-error "exposes TU-local entity" }
24 template <typename T> inline int* f = foo(); // { dg-error "exposes TU-local entity" }