| 1 |
// System header for testing that -Wenum-constexpr-conversion leads to an error |
| 2 |
// when included in user code, or when the system macro is used. |
| 3 |
|
| 4 |
enum SystemEnum |
| 5 |
{ |
| 6 |
a = 0, |
| 7 |
b = 1, |
| 8 |
}; |
| 9 |
|
| 10 |
void testValueInRangeOfEnumerationValuesInSystemHeader() |
| 11 |
{ |
| 12 |
constexpr SystemEnum x1 = static_cast<SystemEnum>(123); |
| 13 |
// expected-error@-1 {{constexpr variable 'x1' must be initialized by a constant expression}} |
| 14 |
// expected-note@-2 {{integer value 123 is outside the valid range of values [0, 1] for the enumeration type 'SystemEnum'}} |
| 15 |
|
| 16 |
const SystemEnum x2 = static_cast<SystemEnum>(123); // ok, not a constant expression context |
| 17 |
} |
| 18 |
|
| 19 |
#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \ |
| 20 |
constexpr SystemEnum system_enum = static_cast<SystemEnum>(123) |