This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-08-31


2932. Value range of empty enumeration

Section: 9.7.1  [dcl.enum]     Status: open     Submitter: Benjamin Sch.     Date: 2024-08-31

(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. [Footnote: ... ]