brintos

brintos / llvm-project-archived public Read only

0
0
Text · 762 B · 7d35d5b Raw
21 lines · c
1// System header for testing that -Wenum-constexpr-conversion leads to an error2// when included in user code, or when the system macro is used.3 4enum SystemEnum5{6    a = 0,7    b = 1,8};9 10void 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 context17}18 19#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \20    constexpr SystemEnum system_enum = static_cast<SystemEnum>(123)21