Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


660. Unnamed scoped enumerations

Section:9.8.1  [dcl.enum]    Status:CD1    Submitter:Daveed Vandevoorde    Date:15 November 2007

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

The current specification of scoped enumerations does not appearto forbid an example like the following, even though the enumeratore cannot be used:

    enum class { e };

This might be covered by 9.1 [dcl.pre] paragraph 3,

In asimple-declaration, theoptionalinit-declarator-list can be omitted only whendeclaring a class (Clause 11 [class]) or enumeration(9.8.1 [dcl.enum]), that is, whenthedecl-specifier-seq contains eitheraclass-specifier, anelaborated-type-specifier with aclass-key (11.3 [class.name]), oranenum-specifier. In these cases and whenever aclass-specifier orenum-specifier is present in thedecl-specifier-seq, the identifiers in these specifiers areamong the names being declared by the declaration(asclass-names,enum-names, orenumerators,depending on the syntax). In such cases, and except for thedeclaration of an unnamed bit-field (11.4.10 [class.bit]), thedecl-specifier-seq shall introduce one or more names into theprogram, or shall redeclare a name introduced by a previousdeclaration.

which, when combined with paragraph 2,

A declaration occurs in a scope (6.4 [basic.scope]); the scoperules are summarized in 6.5 [basic.lookup]. A declaration thatdeclares a function or defines a class, namespace, template, orfunction also has one or more scopes nested within it. These nestedscopes, in turn, can have declarations nested within them. Unlessotherwise stated, utterances in Clause 9 [dcl] aboutcomponents in, of, or contained by a declaration or subcomponentthereof refer only to those components of the declaration thatarenot 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 theconstructs containing a nested scope (although 6.4.8 [basic.scope.enum]does describe “enumeration scope”); furthermore, anenumerator-definition is not formally a “nesteddeclaration.” If unusable scoped enumeration definitions are tobe banned, these shortcomings in 9.1 [dcl.pre] paragraph 2must be addressed. (A note in 9.8.1 [dcl.enum] mentioning thatunnamed scoped enumerations are not allowed would also be helpful.)

Notes from the February, 2008 meeting:

The consensus was to require that theidentifier bepresent in anenum-specifier unless theenum-key isenum.

Proposed resolution (June, 2008):

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

...Theenum-keysenum class andenum structare semantically equivalent; an enumeration type declared with one ofthese is ascoped enumeration, and itsenumerators arescoped enumerators.The optionalidentifier shall not beomitted in the declaration of a scoped enumeration. Thetype-specifier-seq of anenum-base...



[8]ページ先頭

©2009-2026 Movatter.jp