| 1 |
// CWG 2096 - constraints on literal unions. |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
struct literal { }; |
| 5 |
typedef volatile int nonliteral_v; |
| 6 |
struct nonliteral { |
| 7 |
nonliteral() {} |
| 8 |
}; |
| 9 |
|
| 10 |
union U { |
| 11 |
literal l; |
| 12 |
nonliteral n; |
| 13 |
|
| 14 |
constexpr U() : l{} {} |
| 15 |
}; |
| 16 |
|
| 17 |
constexpr U u{}; |
| 18 |
|
| 19 |
union U2 { |
| 20 |
nonliteral n; |
| 21 |
literal l; |
| 22 |
|
| 23 |
constexpr U2() : l{} {} |
| 24 |
}; |
| 25 |
|
| 26 |
constexpr U2 u2{}; |
| 27 |
|
| 28 |
union U3 { // { dg-message "not literal" } |
| 29 |
nonliteral_v n; // { dg-message "volatile type" } |
| 30 |
|
| 31 |
constexpr U3() : n{} {} |
| 32 |
}; |
| 33 |
|
| 34 |
constexpr U3 u3{}; // { dg-error "not literal" } |
| 35 |
|
| 36 |
union U4 { |
| 37 |
nonliteral n; |
| 38 |
nonliteral_v n2; |
| 39 |
literal l; |
| 40 |
nonliteral n3; |
| 41 |
|
| 42 |
constexpr U4() : l{} {} |
| 43 |
}; |
| 44 |
|
| 45 |
constexpr U4 u4{}; |
| 46 |
|
| 47 |
union U5 { |
| 48 |
nonliteral_v n; |
| 49 |
literal l; |
| 50 |
|
| 51 |
constexpr U5() : n{} {} |
| 52 |
}; |
| 53 |
|
| 54 |
constexpr U5 u5{}; |