Created on 2024-08-31.00:00:00 last changed 1 month ago
(From submission #604.)
Consider:
enum E { }; constexpr auto x = static_cast<E>(-1);
It is unclear whether the hypothetical integer type for E is a signed integer type of width 1 or an unsigned integer type of width 0, which does not have a signed counterpart and thus does not exist. The former choice makes the example well-formed, the latter one ill-formed. Before P1236, the specification was clear.
Possible resolution:
Change in 9.7.1 [dcl.enum] paragraph 8 as follows:
For an enumeration whose underlying type is fixed, the values of the enumeration are the values of the underlying type. Otherwise, the:[ Note: It is possible to define an enumeration that has values not defined by any of its enumerators. -- end note ]
- If the enumerator-list is empty, the values of the enumeration are as if the enumeration had a single enumerator with value 0.
- The values of the enumeration are the values representable by a hypothetical integer type with minimal width M such that all enumerators can be represented; if all enumerators have value 0, the values of the enumeration consist of the single value 0 and M is 0. The width of the smallest bit-field large enough to hold all the values of the enumeration type is the maximum of 1 and M.
If the enumerator-list is empty, the values of the enumeration are as if the enumeration had a single enumerator with value 0.[Footnote: ... ]
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-08-31 00:00:00 | admin | create |