Title
Scoped enumerators in integral constant expressions
Status
c++11
Section
7.7 [expr.const]
Submitter
Jonathan Caves

Created on 2010-03-21.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 as part of paper N3260.]

Date: 2011-02-15.00:00:00

Proposed resolution (February, 2011):

This issue is resolved by the resolution of issue 1197.

Date: 2022-09-25.18:08:42

According to 7.7 [expr.const] paragraph 3,

A constant expression is an integral constant expression if it is of integral or enumeration type. [Note: such expressions may be used as array bounds (9.3.4.5 [dcl.array], 7.6.2.8 [expr.new]), as case expressions (8.5.3 [stmt.switch]), as bit-field lengths (11.4.10 [class.bit]), as enumerator initializers (9.7.1 [dcl.enum]), and as integral or enumeration non-type template arguments (13.4 [temp.arg]). —end note]

Although there is conceptually a conversion from enumeration type to integral type involved in using an enumerator as an array bound or bit-field length, the normative wording for those uses does not explicitly mention it and simply requires an integral constant expression. Consequently, the current wording permits uses like the following:

    enum class E { e = 10; };
    struct S {
        int arr[E::e];
        int i: E::e;
    };

This seems surprising.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3314
2011-04-10 00:00:00adminsetstatus: tentatively ready -> fdis
2011-02-28 00:00:00adminsetmessages: + msg3225
2011-02-28 00:00:00adminsetstatus: drafting -> tentatively ready
2010-08-23 00:00:00adminsetstatus: open -> drafting
2010-03-21 00:00:00admincreate