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

2024-03-20


874. Class-scope definitions of enumeration types

Section: 11.4  [class.mem]     Status: CD2     Submitter: Daniel Krügler     Date: 16 April, 2009

[Voted into WP at October, 2009 meeting.]

According to 11.4 [class.mem] paragraph 1,

The enumerators of an enumeration (9.7.1 [dcl.enum]) defined in the class are members of the class... A member shall not be declared twice in the member-specification, except that a nested class or member class template can be declared and then later defined.

The enumerators of a scoped enumeration are not members of the containing class; the wording should be revised to apply only to unscoped enumerations.

The second part of the cited wording from 11.4 [class.mem] prohibits constructs like:

    class C {
      public:
        enum E: int;
      private:
        enum E: int { e0 };
    };

which might be useful in making the enumeration type, but not its enumerators, accessible.

Notes from the July, 2009 meeting:

According to 11.8.2 [class.access.spec] paragraph 4, the access must be the same for all declarations of a class member. The suggested usage given above violates that requirement: the second declaration of E declares the enumeration itself, not just the enumerators, to be private. The CWG did not feel that the utility of the suggested feature warranted the complexity of an exception to the general rule.

Proposed resolution (July, 2009):

  1. Change 11.4 [class.mem] paragraph 1 as follows:

  2. ...The enumerators of an unscoped enumeration (9.7.1 [dcl.enum]) defined in the class are members of the class... A member shall not be declared twice in the member-specification, except that a nested class or member class template can be declared and then later defined, and except that an enumeration can be first introduced with an opaque-enum-declaration and then later be redeclared with an enum-specifier.
  3. Change the example in 11.8.2 [class.access.spec] paragraph 4 as follows:

  4. When a member is redeclared within its class definition, the access specified at its redeclaration shall be the same as at its initial declaration. [Example:

      struct S {
        class A;
        enum E : int;
      private:
        class A { };          // error: cannot change access
        enum E : int { e0 };  // error: cannot change access
      };
    

    end example]