https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69903
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This fixes the crash: template<> template<> void A<B>::f<2>() { volatile int y = 777; }; The code is invalid there is no B::f, only A<B>::f. The problem is GCC is finding the template and still considering it a specialization when it does not match.