Title
Can an enumeration variable have values outside the values of the enumeration?
Status
c++11
Section
9.7.1 [dcl.enum]
Submitter
Jason Merrill

Created on 2010-01-22.00:00:00 last changed 123 months ago

Messages

Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting.]

Date: 2010-11-15.00:00:00

Proposed resolution (November, 2010):

This issue is resolved by the resolution of issue 1094.

Date: 2010-08-23.00:00:00
N3092 comment US 31

According to 9.7.1 [dcl.enum] paragraph 10,

An expression of arithmetic or enumeration type can be converted to an enumeration type explicitly. The value is unchanged if it is in the range of enumeration values of the enumeration type; otherwise the resulting enumeration value is unspecified.

(There is similar wording in 7.6.1.9 [expr.static.cast].) Does the phrase “resulting enumeration value” mean that the result, although unspecified, must lie within the range of enumeration values of the enumeration type? Existing practice seems to allow out-of-range values to be preserved if the underlying type is large enough to represent the value. This freedom is important both for efficiency (to avoid having to mask values while storing and/or fetching) and to prevent optimizers from removing code that tests for out-of-range values.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3334
2011-04-10 00:00:00adminsetstatus: ready -> fdis
2010-11-29 00:00:00adminsetstatus: review -> ready
2010-08-23 00:00:00adminsetmessages: + msg2828
2010-08-23 00:00:00adminsetstatus: open -> review
2010-01-22 00:00:00admincreate