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


862. Undefined behavior with enumerator value overflow

Section: 9.7.1  [dcl.enum]     Status: CD2     Submitter: Daniel Krügler     Date: 7 April, 2009

[Voted into WP at October, 2009 meeting.]

The type of an enumerator that has no initializing value in an enumeration whose underlying type is not fixed is given by the third bullet of 9.7.1 [dcl.enum] paragraph 5:

the type of the initializing value is the same as the type of the initializing value of the preceding enumerator unless the incremented value is not representable in that type, in which case the type is an unspecified integral type sufficient to contain the incremented value.

This does not address the case in which there is no such type, meaning that it is apparently undefined behavior. Other cases in which an enumeration value is unrepresentable are made ill-formed (see the preceding paragraph for an enumeration with a fixed underlying type and the following paragraph for the case in which the minimum and maximum values cannot be represented by a single type). It would be better if this case were ill-formed as well, instead of causing undefined behavior.

Proposed resolution (July, 2009):

Change 9.7.1 [dcl.enum] paragraph 5, bullet 3 as follows: