Skip to content

Type of an enumerator inside the declaration of its enumeration - a conflict #1845

@h0nzZik

Description

@h0nzZik

I believe that [expr.prim.id.qual]/4

A nested-name-specifier that denotes an enumeration (10.2), followed by the name of an enumerator of that enumeration, is a qualified-id that refers to the enumerator. The result is the enumerator. The type of the result is the type of the enumeration. The result is a prvalue.

is in conflict with [dcl.enum]/5

Each enumeration defines a type that is different from all other types. Each enumeration also has an underlying type. The underlying type can be explicitly specified using an enum-base. For a scoped enumeration type, the underlying type is int if it is not explicitly specified. In both of these cases, the underlying type is said to be fixed. Following the closing brace of an enum-specifier, each enumerator has the type of its enumeration. If the underlying type is fixed, the type of each enumerator prior to the closing brace is the underlying type and the constant-expression in the enumerator-definition shall be a converted constant expression of the underlying type (8.20). [...]

in this example:

enum class E {
    A,
    B = E::A // what is the type of E::A?
};

The clang and gcc seem to follow [dcl.enum]/5. The two parts would not be in conflict if the [expr.prim.id.qual]/4 said:

[...] The type of the result is the type of the enumerator. [...]

It was discussed on StackOverflow a few months ago.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions