Files
clang-p2996/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
Carlos Galvez e7a6171c4c [clang] Enable Wenum-constexpr-conversion also in system headers and … (#67528)
…macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that people
are aware of it and can work on it.
2023-10-14 14:19:20 +02:00

20 lines
665 B
C++

// System header for testing that -Wenum-constexpr-conversion leads to an error
// when included in user code, or when the system macro is used.
enum SystemEnum
{
a = 0,
b = 1,
};
void testValueInRangeOfEnumerationValuesInSystemHeader()
{
constexpr SystemEnum x1 = static_cast<SystemEnum>(123);
// expected-error@-1 {{integer value 123 is outside the valid range of values [0, 1] for the enumeration type 'SystemEnum'}}
const SystemEnum x2 = static_cast<SystemEnum>(123); // ok, not a constant expression context
}
#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
constexpr SystemEnum system_enum = static_cast<SystemEnum>(123)