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

2024-12-19


1765. Overflow of enumeration used as enumerator value

Section: 9.7.1  [dcl.enum]     Status: C++14     Submitter: Canada     Date: 2013-09-23

N3690 comment CA 7

[Moved to DR at the February, 2014 meeting.]

Regarding the value of an enumerator whose enumeration's underlying type is not fixed, 9.7.1 [dcl.enum] paragraph 5 says,

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.

It is not clear how this is to be applied when the preceding enumerator value is given by an enumerator whose value is the largest of its enumeration's values, and there is implementation variance on this point.

Proposed resolution (September, 2013):

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

...If the underlying type is fixed, the type of each enumerator enumerator prior to the closing brace is the underlying type and the constant-expression in the enumerator-definition shall be a converted constant expression of the underlying type (7.7 [expr.const]); if the initializing value of an enumerator cannot be represented by the underlying type, the program is ill-formed. If the underlying type is not fixed, the type of each enumerator prior to the closing brace is the type of its initializing value determined as follows: