In C++, specifically in C++14 n4296, there are two paragraps talking about type of an enumerator, which seem to be contradictory to me. See 7.2/5 (which is 10.2/5 in n4659
):
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 [...]
And 5.1.1/11 (which is 8.1.4.2/4 in n4659
) writes:
A nested-name-specifier that denotes an enumeration (7.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.
Then, what happens when we refer to an enumerator through nested-name-specifier prior to closing brace of the declaration? Take for example the following snippet:
template < typename T1, typename T2 >
struct fail_if_not_same {
static_assert(std::is_same<T1, T2>::value, "Fail!");
static constexpr int value = 0;
};
enum class E : short {
A,
B = A + 1,
C = fail_if_not_same<decltype(B), short>::value,
D = fail_if_not_same<decltype(E::B), short>::value
};
What is the type of the expression E::B
above? Is this a contradiction in standard? Both gcc and clang follows the 7.2/5.