Unnamed scoped enumerations
9.7.1 [dcl.enum]
Daveed Vandevoorde

Created on 2007-11-15.00:00:00 last changed 161 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):

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

...The enum-keys enum class and enum struct are semantically equivalent; an enumeration type declared with one of these is a scoped enumeration, and its enumerators are scoped enumerators. The optional identifier shall not be omitted in the declaration of a scoped enumeration. The type-specifier-seq of an enum-base...
Date: 2008-02-15.00:00:00

Notes from the February, 2008 meeting:

The consensus was to require that the identifier be present in an enum-specifier unless the enum-key is enum.

Date: 2020-12-15.00:00:00

The current specification of scoped enumerations does not appear to forbid an example like the following, even though the enumerator e cannot be used:

    enum class { e };

This might be covered by Clause 9 [dcl.dcl] paragraph 3,

In a simple-declaration, the optional init-declarator-list can be omitted only when declaring a class (clause Clause 11 [class]) or enumeration (9.7.1 [dcl.enum]), that is, when the decl-specifier-seq contains either a class-specifier, an elaborated-type-specifier with a class-key (11.3 [class.name]), or an enum-specifier. In these cases and whenever a class-specifier or enum-specifier is present in the decl-specifier-seq, the identifiers in these specifiers are among the names being declared by the declaration (as class-names, enum-names, or enumerators, depending on the syntax). In such cases, and except for the declaration of an unnamed bit-field (11.4.10 [class.bit]), the decl-specifier-seq shall introduce one or more names into the program, or shall redeclare a name introduced by a previous declaration.

which, when combined with paragraph 2,

A declaration occurs in a scope (6.4 [basic.scope]); the scope rules are summarized in 6.5 [basic.lookup]. A declaration that declares a function or defines a class, namespace, template, or function also has one or more scopes nested within it. These nested scopes, in turn, can have declarations nested within them. Unless otherwise stated, utterances in clause Clause 9 [dcl.dcl] about components in, of, or contained by a declaration or subcomponent thereof refer only to those components of the declaration that are not nested within scopes nested within the declaration.

appears to rule out the similar class definition,

    struct { int m; };

However, a scoped enumeration is not listed in paragraph 2 among the constructs containing a nested scope (although 6.4.7 [basic.scope.enum] does describe “enumeration scope”); furthermore, an enumerator-definition is not formally a “nested declaration.” If unusable scoped enumeration definitions are to be banned, these shortcomings in Clause 9 [dcl.dcl] paragraph 2 must be addressed. (A note in 9.7.1 [dcl.enum] mentioning that unnamed scoped enumerations are not allowed would also be helpful.)

Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1820
2008-10-05 00:00:00adminsetstatus: ready -> cd1
2008-06-29 00:00:00adminsetmessages: + msg1681
2008-06-29 00:00:00adminsetstatus: drafting -> ready
2008-03-17 00:00:00adminsetmessages: + msg1606
2008-03-17 00:00:00adminsetstatus: open -> drafting
2007-11-15 00:00:00admincreate