You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a template, a member template or a member of a class template is explicitly specialized, a declaration of that specialization shall be reachable from every use of that specialization that would cause an implicit instantiation to take place, in every translation unit in which such a use occurs; no diagnostic is required.
Consider the formal example after the above rule
template<classT> structA {
enum E : T;
enumclassS : T;
};
template<> enum A<int>::E : int { eint }; // OKtemplate<> enumclassA<int>::S : int { sint }; // OKtemplate<classT> enum A<T>::E : T { eT };
template<classT> enumclassA<T>::S : T { sT };
template<> enum A<char>::E : char { echar }; // error: A<char>::E was instantiated// when A<char> was instantiatedtemplate<> enumclassA<char>::S : char { schar }; // OK
The remark says the last line is ok. Isn't that A<char> doesn't cause the implicit instantiation of S? As per [temp.inst] p3
The implicit instantiation of a class template specialization causes
the implicit instantiation of the declarations, but not of the definitions, of the non-deleted class member functions, member classes, scoped member enumerations, static data members, member templates, and friends; and
the implicit instantiation of the definitions of deleted member functions, unscoped member enumerations, and member anonymous unions.
Hence, presumably, the intent of [temp.expl.spec] p7 does not refer to an arbitrary implicit instantiation. Consider the second case
template<classT> structA {
enum E : T;
enumclassS : T;
};
template<> enum A<int>::E : int { eint }; // OKtemplate<> enumclassA<int>::S : int { sint }; // OK// template<class T> enum A<T>::E : T { eT }; comment this definitiontemplate<classT> enumclassA<T>::S : T { sT };
template<> enum A<char>::E : char { echar }; // OKtemplate<> enumclassA<char>::S : char { schar }; // OK
If we comment the definition of A<T>::E, then the explicit specialization template<> enum A<char>::E : char { echar }; is also ok(both in GCC and Clang). So, Is the following rule the original intent of [temp.expl.spec] p7?
If a template, a member template or a member of a class template is explicitly specialized, a declaration of that specialization shall be reachable from every use of that specialization that would cause an implicit instantiation of the definition to take place and the entity whose specialization is being implicit instantiated has been defined at the point of instantiation, in every translation unit in which such a use occurs; no diagnostic is required.
The text was updated successfully, but these errors were encountered:
[temp.expl.spec]
Consider the formal example after the above rule
The remark says the last line is ok. Isn't that
A<char>
doesn't cause the implicit instantiation ofS
? As per [temp.inst] p3Hence, presumably, the intent of [temp.expl.spec] p7 does not refer to an arbitrary implicit instantiation. Consider the second case
If we comment the definition of
A<T>::E
, then the explicit specializationtemplate<> enum A<char>::E : char { echar };
is also ok(both in GCC and Clang). So, Is the following rule the original intent of [temp.expl.spec] p7?The text was updated successfully, but these errors were encountered: