Explicit conversion from a scoped enumeration type to integral type
Section [expr.static.cast]
Daveed Vandevoorde

Created on 2007-12-22.00:00:00 last changed 162 months ago


Date: 2008-09-15.00:00:00

[Voted into the WP at the September, 2008 meeting.]

Date: 2008-06-15.00:00:00

Proposed resolution (June, 2008):

Add the following as a new paragraph following [expr.static.cast] paragraph 8:

A value of a scoped enumeration type (9.7.1 [dcl.enum]) can be explicitly converted to an integral type. The value is unchanged if the original value can be represented by the specified type. Otherwise, the resulting value is unspecified.
Date: 2008-10-05.00:00:00

There appears to be no provision in the Standard for explicit conversion of a value of a scoped enumeration type to an integral type, even though the inverse conversion is permitted. That is,

    enum class E { e };
    static_cast<E>(0);       // #1: OK
    static_cast<int>(E::e);  // #2: error

This is because values of scope enumeration types (intentionally) cannot be implicitly converted to integral types (7.3.7 [conv.prom] and 7.3.9 [conv.integral]) and [expr.static.cast] was not updated to permit #2, although #1 is covered by paragraph 8.

Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1810
2008-10-05 00:00:00adminsetstatus: ready -> cd1
2008-06-29 00:00:00adminsetmessages: + msg1678
2008-06-29 00:00:00adminsetstatus: drafting -> ready
2008-03-17 00:00:00adminsetstatus: open -> drafting
2007-12-22 00:00:00admincreate