commit 5dbbdeda316eaa8f2b2a43fc28762f7d7ecca22c Author: Jason Merrill Date: Wed Apr 1 10:14:53 2015 -0400 PR c++/65646 * decl.c (grokvardecl): Don't call check_explicit_specialization for non-template members of a class template. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f05aefa..31b8e0c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8210,7 +8210,9 @@ grokvardecl (tree type, DECL_INTERFACE_KNOWN (decl) = 1; // Handle explicit specializations and instantiations of variable templates. - if (orig_declarator) + if (orig_declarator + /* For GCC 5 fix 65646 this way. */ + && current_tmpl_spec_kind (template_count) != tsk_none) decl = check_explicit_specialization (orig_declarator, decl, template_count, 0); diff --git a/gcc/testsuite/g++.dg/template/static36.C b/gcc/testsuite/g++.dg/template/static36.C new file mode 100644 index 0000000..36c48b0 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/static36.C @@ -0,0 +1,4 @@ +// PR c++/65646 + +template class A {}; +template <> A<> &A<>::a; // { dg-error "" }