We should check whether the template we're trying to specialize is the
right kind of template.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit af5860b1a4bac653093a74d97a00b162c2b1add7
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Dec 9 12:53:26 2014 -0500
PR c++/64129
* decl.c (grokdeclarator): Recover from variable template
specialization declared as function.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5639b3d..9659336 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10739,6 +10739,19 @@ grokdeclarator (const cp_declarator *declarator,
return error_mark_node;
}
+ if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
+ {
+ tree tmpl = TREE_OPERAND (unqualified_id, 0);
+ if (variable_template_p (tmpl))
+ {
+ error ("specialization of variable template %qD "
+ "declared as function", tmpl);
+ inform (DECL_SOURCE_LOCATION (tmpl),
+ "variable template declared here");
+ return error_mark_node;
+ }
+ }
+
/* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
function_context = (ctype != NULL_TREE) ?
decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/parse/error56.C b/gcc/testsuite/g++.dg/parse/error56.C
new file mode 100644
index 0000000..7c81ab4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/error56.C
@@ -0,0 +1,5 @@
+// PR c++/64129
+
+template <0> int __copy_streambufs_eof; // { dg-error "" }
+class {
+ friend __copy_streambufs_eof <> ( // { dg-error "" }