Title
Converting floating-point values to scoped enumeration types
Status
c++11
Section
7.6.1.9 [expr.static.cast]
Submitter
Daniel Krügler

Created on 2010-07-17.00:00:00 last changed 96 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):

  1. Change 7.6.1.9 [expr.static.cast] paragraph 10 as follows:

  2. A value of integral or enumeration type can be explicitly converted to an enumeration type. The value is unchanged if the original value is within the range of the enumeration values (9.7.1 [dcl.enum]). Otherwise, the resulting enumeration value is unspecified (and might not be in that range). A value of floating-point type can also be converted to an enumeration type. The resulting value is the same as converting the original value to the underlying type of the enumeration (7.3.11 [conv.fpint]), and subsequently to the enumeration type.
  3. Add the following footnote to the end of 9.7.1 [dcl.enum] paragraph 7:

  4. ...If the enumerator-list is empty, the values of the enumeration are as if the enumeration had a single enumerator with value 0. [Footnote: This set of values is used to define promotion and conversion semantics for the enumeration type; it does not exclude an expression of enumeration type from having a value that falls outside this range. —end footnote]
  5. Delete 9.7.1 [dcl.enum] paragraph 10:

  6. 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.
Date: 2016-02-15.00:00:00

According to 9.7.1 [dcl.enum] paragraph 10,

An expression of arithmetic or enumeration type can be converted to an enumeration type explicitly.

However, 7.6.1.9 [expr.static.cast] paragraph 10 says only,

A value of integral or enumeration type can be explicitly converted to an enumeration type.

This omits floating-point values. Presumably unscoped enumeration types are covered by paragraph 7,

The inverse of any standard conversion sequence (Clause 7.3 [conv]), other than the lvalue-to-rvalue (7.3.2 [conv.lval]), array-to- pointer (7.3.3 [conv.array]), function-to-pointer (7.3.4 [conv.func]), and boolean (7.3.14 [conv.fctptr]) conversions, can be performed explicitly using static_cast.

because 7.3.11 [conv.fpint] paragraph 2 allows an unscoped enumeration value to be implicitly converted to a floating point type. (Although that also covers the integral types, so it's not clear why they would be mentioned specifically in 7.6.1.9 [expr.static.cast] paragraph 10.) However, this should presumably say “arithmetic” instead of “integral” to match the statement in 9.7.1 [dcl.enum] paragraph 10.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3311
2011-04-10 00:00:00adminsetstatus: ready -> fdis
2010-11-29 00:00:00adminsetmessages: + msg3051
2010-11-29 00:00:00adminsetstatus: open -> ready
2010-07-17 00:00:00admincreate