The following invalid line of code is accepted since at least gcc 2.95.x: =========================== template<> int i; ===========================
Confirmed.
So is: struct A { }; template<> A i; which means the specilization syntax does not mandate a need the qualifying class needs to be a template type. That looks interesting!!!
From the C++ standard draft specification An explicit specialization of any of the following: — function template — class template — member function of a class template — static data member of a class template — member class of a class template — member class template of a class template — member function template of a class template can be declared by a declaration introduced by template<>; that is: explicit specialization: template < > declaration Hence this is a bug.
*** Bug 41875 has been marked as a duplicate of this bug. ***
Looking into it.
Author: jason Date: Fri Aug 31 21:35:33 2012 New Revision: 190842 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190842 Log: PR c++/18747 * pt.c (check_template_variable): New. (num_template_headers_for_class): Split out... * decl.c (grokdeclarator): ...from here. (start_decl): Remove redundant diagnostic. * cp-tree.h: Declare them * parser.c (cp_parser_single_declaration): Call check_template_variable. . Added: trunk/gcc/testsuite/g++.dg/parse/error50.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cp-tree.h trunk/gcc/cp/decl.c trunk/gcc/cp/parser.c trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Ah, this is fixed, then.