Closed alexv-ds closed 1 month ago
I've also hit this and have a bit more context as to why this has become an issue.
to_int
casts an integer to an enum value, clang incorrectly used to allow any integer value to be cast to an enum value at compile time, since 20 clang now refuses to instantiate enum values at compile time with a value not in the representable bit range of enum values. C++ (since 20?) specifies that enums are at least as large as the minimum number of bits required to represent all values in 2s complement.
This means its no longer enough to use FLECS_ENUM_MAX(E)
as an upper bound, some other way will need to be used to prevent going out of range. std::numeric_limits<std::underlying_type_t<E>>
won't be enough because it'll round up to the nearest 8 bits, and even going 1 bit out of range triggers this compiler error.
magic_enum ran into the same issue, this looks like a potential fix: https://github.com/Neargye/magic_enum/blob/master/include/magic_enum/magic_enum.hpp#L626
Fixed!
Describe the bug Compilation error
To Reproduce Steps to reproduce the behavior:
Additional context tested on - clang-20, ubuntu-24.04