https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116981
Bug ID: 116981
Summary: wrongly accepted non-more-specialized partial
specialization of class template member for an
instantiated enclosing template
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ing.russomauro at gmail dot com
Target Milestone: ---
The following code is refused by clang 19.1 and msvc 19.40, but accepted by gcc
14.2
template<class T1> class A {
public:
template<class T2> class B {
public:
void func();
};
};
// template class A3<char>; regardless of the instantiation of A<char> is
explicit or implicit.
template<> template<class T2> struct A<char>::B<T2>{ void func2(); };
The point is that the last line is defining a partial specialization, which is
not more specialized compared to the primary template whose declaration is
instantiated for A<char> as from the primary template of A.
As additional detail, by trying to use A<char>::B<int>, gcc ignores that
specialization and prefers the primary template, being able to invoke func()
and not func2().