mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
CWG1766 made out-of-range cast to enumeration without fixed underlying type raise undefined behavior. Such UB arguably also applies to `bit_cast`, although it's not required that UB in `bit_cast` makes the expression non-constant. Currently, only Clang has implemented CWG1766, while Clang's underlying `__builtin_bit_cast` happens to be a workaround. However, it's more reliable to me to rely on the guarantee that core language UB causes constant evaluation failure. The approach in this patch effectively detects whether `std::integral_constant<E, static_cast<E>(V)>` is a valid type, which is equivalent to whether `static_cast<E>(V)` is a constant expression. When the answer is `false`, value `V` can't be an enumerator of `E`. |
||
|---|---|---|
| .. | ||
| magic_enum | ||