-
Notifications
You must be signed in to change notification settings - Fork 500
Closed
Labels
invalidThis doesn't seem rightThis doesn't seem right
Description
Clang has recently addressed an llvm/llvm-project#50055 where it failed to diagnose the UB of casting an out-of-range integer to an enum in a constant expression.
Since undefined behavior is not allowed in a constant expression, Clang now prohibits enum test { zero }; constexpr int g = static_cast<test>(-1);
with error: constexpr variable 'g' must be initialized by a constant expression; note: integer value -1 is outside the valid range of values [0, 1] for this enumeration type
This change breaks magic_enum library, since the library internally uses the [-128, 128]
default enum value range. Demonstrated with example, below
#include "magic_enum.hpp"
enum Color { Red, Black };
int main(int argc, char* argv[]) {
Color color = Red;
magic_enum::enum_name(color);
return 0;
}
Metadata
Metadata
Assignees
Labels
invalidThis doesn't seem rightThis doesn't seem right