https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93914
Bug ID: 93914
Summary: invalid definition of explicit specialization accepted
with just a warning
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The invalid definition of the explicit specialization of A below is accepted
with just a warning. It should be rejected not just because it's malformed
(and the meaning is unclear) but also because (assuming it defines an explicit
specialization) the template specialization has already been instantiated by
defining the variable a (same as in the case of B).
$ cat z.C && gcc -O2 -S -Wall z.C
template <class> struct A { };
A<int> a;
template <> struct A<int> A { }; // invalid
template <class> struct B { };
B<int> b;
template <> struct B<int> { };
z.C:3:27: warning: too many template headers for ‘A’ (should be 0)
3 | template <> struct A<int> A { }; // invalid
| ^
z.C:7:20: error: specialization of ‘B<int>’ after instantiation
7 | template <> struct B<int> { };
| ^~~~~~
z.C:7:20: error: redefinition of ‘struct B<int>’
z.C:5:25: note: previous definition of ‘struct B<int>’
5 | template <class> struct B { };
| ^