| 1 |
// PR c++/119996 |
| 2 |
// { dg-additional-options "-fmodules" } |
| 3 |
// { dg-module-cmi !M } |
| 4 |
// Similar to internal-11.C, but for potentially-constant variables. |
| 5 |
|
| 6 |
export module M; |
| 7 |
|
| 8 |
static int tu_local = 5; |
| 9 |
static int& foo() { return tu_local; } |
| 10 |
|
| 11 |
// For implementation reasons, we adjust [basic.link] p14.2 to restrict ignored |
| 12 |
// exposures to non-inline variables, since for inline variables without |
| 13 |
// dynamic initialisation we need to emit their initialiser for importer use. |
| 14 |
|
| 15 |
int& a = tu_local; // OK |
| 16 |
inline int& b = tu_local; // { dg-error "initialized to a TU-local value" } |
| 17 |
inline auto& bf = foo; // { dg-error "initialized to a TU-local value" } |
| 18 |
|
| 19 |
// But dynamic initialisers are fine, importers will just treat them as external. |
| 20 |
inline int& c = foo(); // OK |
| 21 |
|
| 22 |
// For consistency, we follow the same rules with templates, noting that |
| 23 |
// we still need to emit definitions with dynamic initializers so we error. |
| 24 |
template <typename T> int& d = tu_local; // OK |
| 25 |
template <typename T> inline int& e = tu_local; // { dg-error "exposes TU-local entity" } |
| 26 |
template <typename T> inline int& f = foo(); // { dg-error "exposes TU-local entity" } |
| 27 |
template <typename T> inline auto& ff = foo; // { dg-error "exposes TU-local entity" } |
| 28 |
|
| 29 |
// Note that non-references are OK, because an integer or enumeration |
| 30 |
// value is never TU-local: we fold these expressions early |
| 31 |
// (as we should, by [basic.link] p14.4). |
| 32 |
static const int const_val = 123; |
| 33 |
inline const int potentially_constant = const_val; // OK |