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

2024-11-11


1636. Bits required for negative enumerator values

Section: 9.7.1  [dcl.enum]     Status: CD5     Submitter: Hyman Rosen     Date: 2013-03-07

[Accepted as a DR at the November, 2018 (San Diego) meeting.]

According to 9.7.1 [dcl.enum] paragraph 7,

For an enumeration whose underlying type is fixed, the values of the enumeration are the values of the underlying type. Otherwise, for an enumeration where emin is the smallest enumerator and emax is the largest, the values of the enumeration are the values in the range bmin to bmax, defined as follows: Let K be 1 for a two's complement representation and 0 for a one's complement or sign-magnitude representation. bmax is the smallest value greater than or equal to max(|emin|-K,|emax|) and equal to 2M-1, where M is a non-negative integer. bmin is zero if emin is non-negative and -(bmax+K) otherwise. The size of the smallest bit-field large enough to hold all the values of the enumeration type is max(M,1) if bmin is zero and M+1 otherwise.

The result of these calculations is that the number of bits required for

  enum { N = -1, Z = 0 }

is 1, but the number required for

  enum { N = -1 }

is 2. This is surprising. This could be fixed by changing |emax| to emax.

Proposed resolution (June, 2018):

Change 9.7.1 [dcl.enum] paragraph 8 as follows:

bmax is the smallest value greater than or equal to max(|emin| - K, |emax|) , emax) and equal to 2M - 1, where M is a non-negative integer.