What is the function of const specifier in enum types?

Viewed 550
enum foo : const unsigned int
{
    F,
    S,
    T
};

void func()
{
    foo p;
    p = F;
}

The above compiles so the underlying type is not a const type?

1 Answers

The const qualifier is ignored in the specification of enum-base; which just expects an integral type to be used as the underlying type of the enumeration type, specifying const (or volatile) doesn't make much sense.

(emphasis mine)

colon (:), followed by a type-specifier-seq that names an integral type (if it is cv-qualified, qualifications are ignored) that will serve as the fixed underlying type for this enumeration type

From the standard, [dcl.enum]/2:

(emphasis mine)

The type-specifier-seq of an enum-base shall name an integral type; any cv-qualification is ignored.

Related