http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57746
Bug ID: 57746 Summary: rejected valid specialization of member function of class template (I think) Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: luto at mit dot edu Note: I could easily be wrong here... template<typename T> struct X { static int val; static void func(); }; extern template struct X<int>; template<> int X<int>::val = 5; // OK template<> void X<int>::func() {} // Error g++ 4.7.2 and some pre-4.8 build say "error: specialization of ‘static void X<T>::func() [with T = int]’ after instantiation". Oddly, both accept the specialization of val. clang++ rejects both. The relevant part of the standard is probably [temp.explicit.4], which says: A declaration of a function template, a member function or static data member of a class template, or a member function template of a class or class template shall precede an explicit instantiation of that entity. A definition of a class template, a member class of a class template, or a member class template of a class or class template shall precede an explicit instantiation of that entity unless the explicit instantiation is preceded by an explicit specialization of the entity with the same template arguments. If the declaration of the explicit instantiation names an implicitly-declared special member function (Clause 12), the program is ill-formed. The two specializations are definitions, not declarations, as far as I know. Therefore, [temp.explicit.4] shouldn't apply.