| 1 |
// PR c++/91353 - P1331R2: Allow trivial default init in constexpr contexts. |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
struct S { |
| 5 |
int a = 1; |
| 6 |
constexpr S() = default; |
| 7 |
}; |
| 8 |
|
| 9 |
constexpr S s; |
| 10 |
|
| 11 |
union U { |
| 12 |
int a = 1; |
| 13 |
constexpr U() = default; |
| 14 |
}; |
| 15 |
|
| 16 |
constexpr U u; |
| 17 |
|
| 18 |
struct S2 { |
| 19 |
int a; |
| 20 |
constexpr S2() = default; |
| 21 |
}; |
| 22 |
|
| 23 |
constexpr S2 s2; // { dg-error "uninitialized .const s2." } |
| 24 |
|
| 25 |
union U2 { |
| 26 |
int a; |
| 27 |
constexpr U2() = default; |
| 28 |
}; |
| 29 |
|
| 30 |
constexpr U2 u2; // { dg-error "uninitialized .const u2." } |
| 31 |
|
| 32 |
struct S3 { |
| 33 |
// FIXME if it's anonymous union, we don't give the error below |
| 34 |
union { |
| 35 |
int a; |
| 36 |
} u; |
| 37 |
constexpr S3() = default; |
| 38 |
}; |
| 39 |
|
| 40 |
constexpr S3 s3; // { dg-error "uninitialized .const s3." } |
| 41 |
|
| 42 |
struct S4 { |
| 43 |
// FIXME if it's anonymous union, we don't give the error below |
| 44 |
union { |
| 45 |
int n; |
| 46 |
} u; |
| 47 |
constexpr S4() = default; |
| 48 |
}; |
| 49 |
|
| 50 |
constexpr S4 s4; // { dg-error "uninitialized .const s4." } |
| 51 |
|
| 52 |
struct S5 { |
| 53 |
union { |
| 54 |
int n = 0; |
| 55 |
}; |
| 56 |
// FIXME if it's anonymous union, we don't give the error below |
| 57 |
union { |
| 58 |
int m; |
| 59 |
} u; |
| 60 |
constexpr S5() = default; |
| 61 |
}; |
| 62 |
|
| 63 |
constexpr S5 s5; // { dg-error "uninitialized .const s5.|not a constant expression" } |