1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-21 01:24:21 +00:00
magic_enum/include
A. Jiang b96c47f8c7 More reliable value validness detection towards CWG1766
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`.
2025-01-24 17:00:49 +08:00
..
magic_enum More reliable value validness detection towards CWG1766 2025-01-24 17:00:49 +08:00