From 59bce71381be24449aaf902bc1bc64a12b373bf4 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 9 Dec 2014 21:51:03 -0500 Subject: [PATCH] re PR c++/64129 (ICE on invalid: in grokfndecl, at cp/decl.c:7658) PR c++/64129 * decl.c (grokdeclarator): Recover from variable template specialization declared as function. From-SVN: r218557 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/decl.c | 13 +++++++++++++ gcc/testsuite/g++.dg/parse/error56.C | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/error56.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8a8b536a53d..484dd286369 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2014-12-09 Jason Merrill + PR c++/64129 + * decl.c (grokdeclarator): Recover from variable template + specialization declared as function. + PR c++/64222 * parser.c (cp_parser_unqualified_id): Don't declare fname while parsing function parms. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5639b3d54c8..9659336f01d 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 00000000000..7c81ab4488f --- /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 "" } -- 2.30.2