I have the following example that I've decomposed from §14.7.3/6 [temp.expl.spec]
that defines a class member enumeration in the primary template and subsequently specializes it. The following doesn't compile in clang:
template<class T>
struct A {
enum E : T;
};
template<class T>
enum A<T>::E : T { eT };
template<>
enum A<char>::E : char { echar }; // ill-formed, A<char>::E was instantiated
// when A<char> was instantiated
// error: explicit specialization of 'E' after instantiation
The reason is supposed to be that the definition of the unscoped member enumeration was instantiated before the specialization. 14.7.1 [temp.inst]/1:
The implicit instantiation of a class template specialization causes the implicit instantiation of [...] the definitions of unscoped member enumerations and member anonymous unions.
I'm trying to understand why that is a problem exactly. Is it because if the enumeration already has a definition, then that would cause a redefinition error during the specialization?
::
scope resolution operator applied to a nested-name-specifier that denotes its class, namespace, or enumeration." So the general rule is that forA<int>::@
, an unscoped enumeration member can be found as a name@
. Typically, this implies that the enumeration has to be instantiated. Possibly, you could add a special rule for name lookup during the definition of anenum
. – dyp