| 1 |
// PR c++/91360 - Implement C++20 P1143R2: constinit |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// Check that we preserve DECL_DECLARED_CONSTINIT_P in duplicate_decls. |
| 4 |
|
| 5 |
int gl = 42; |
| 6 |
|
| 7 |
struct S { |
| 8 |
constinit static int m; |
| 9 |
constinit static int n; |
| 10 |
constinit static const int &r1; |
| 11 |
constinit static const int &r2; |
| 12 |
}; |
| 13 |
|
| 14 |
int S::m = 42; |
| 15 |
int nonconst; |
| 16 |
constinit int S::n = nonconst; // { dg-error "variable .S::n. does not have a constant initializer" } |
| 17 |
// { dg-error "not usable in a constant expression" "" { target *-*-* } .-1 } |
| 18 |
|
| 19 |
const int &S::r1 = gl; |
| 20 |
const int &S::r2 = 42; |
| 21 |
|
| 22 |
struct T { |
| 23 |
constinit static thread_local const int &r1; |
| 24 |
constinit static thread_local const int &r2; |
| 25 |
}; |
| 26 |
constinit thread_local const int &T::r1 = gl; |
| 27 |
constinit thread_local const int &T::r2 = 42; // { dg-error "variable .T::r2. does not have a constant initializer|not a constant expression" } |