| 1 |
// PR c++/91360 - Implement C++20 P1143R2: constinit |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
constinit constinit int v1; // { dg-error "duplicate .constinit." } |
| 5 |
constexpr constinit int v2 = 1; // { dg-error "can use at most one of the .constinit. and .constexpr. specifiers" } |
| 6 |
constinit constexpr int v3 = 1; // { dg-error "an use at most one of the .constinit. and .constexpr. specifiers" } |
| 7 |
|
| 8 |
extern static constinit int v4; // { dg-error "'static' specifier conflicts with 'extern'" } |
| 9 |
extern thread_local constinit int v5; |
| 10 |
extern constinit int v6; |
| 11 |
|
| 12 |
constinit typedef int T; // { dg-error ".constinit. cannot appear in a typedef declaration" } |
| 13 |
|
| 14 |
struct S2 { |
| 15 |
constinit int m1; // { dg-error "non-static data member .m1. declared .constinit." } |
| 16 |
constinit unsigned int b : 32; // { dg-error " non-static data member .b. declared .constinit." } |
| 17 |
}; |
| 18 |
|
| 19 |
struct S3 { |
| 20 |
constinit S3() {} // { dg-error ".constinit. on function return type is not allowed" } |
| 21 |
constinit ~S3() {} // { dg-error ".constinit. on function return type is not allowed" } |
| 22 |
}; |
| 23 |
|
| 24 |
constinit struct S4 { // { dg-error ".constinit. cannot be used for type declarations" } |
| 25 |
}; |
| 26 |
|
| 27 |
template<constinit int I> // { dg-error "a parameter cannot be declared .constinit." } |
| 28 |
struct X { }; |
| 29 |
|
| 30 |
int |
| 31 |
fn1 () |
| 32 |
{ |
| 33 |
// Not static storage |
| 34 |
constinit int a1 = 42; // { dg-error "17:.constinit. can only be applied to a variable with static or thread storage" } |
| 35 |
constinit int a2 = 42; // { dg-error "17:.constinit. can only be applied to a variable with static or thread storage" } |
| 36 |
extern constinit int e1; |
| 37 |
|
| 38 |
return 0; |
| 39 |
} |
| 40 |
|
| 41 |
constinit int // { dg-error ".constinit. on function return type is not allowed" } |
| 42 |
fn3 () |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
void |
| 47 |
fn2 (int i, constinit int p) // { dg-error "a parameter cannot be declared .constinit." } |
| 48 |
{ |
| 49 |
constinit auto l = [i](){ return i; }; // { dg-error "18:.constinit. can only be applied to a variable with static or thread storage" } |
| 50 |
} |
| 51 |
|
| 52 |
struct B { int d; }; |
| 53 |
|
| 54 |
void |
| 55 |
fn3 (B b) |
| 56 |
{ |
| 57 |
constinit auto [ a ] = b; // { dg-error ".constinit. can only be applied to a variable with static or thread storage" } |
| 58 |
} |