Hi,
here we want to reject meaningless things like:
template<> int i; // { dg-error "template" }
struct A
{
};
template<> A j; // { dg-error "template" }
It seems to me that a good place to do that is toward the end of
cp_parser_single_declaration, where we have only to be careful with
static data members (otherwise, eg, debug/static1.C regresses
immediately). I'm not sure about the error message...
The below bootstraps and tests fine on x86_64-linux.
Thanks,
Paolo.
/////////////////////
/cp
2012-08-23 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/18747
* parser.c (cp_parser_single_declaration): When trying for template
functions, reject VAR_DECLs (besides static data members).
/testsuite
2012-08-23 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/18747
* g++.dg/parse/error50.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 190618)
+++ cp/parser.c (working copy)
@@ -21429,6 +21429,15 @@ cp_parser_single_declaration (cp_parser* parser,
"explicit template specialization cannot have a storage
class");
decl = error_mark_node;
}
+
+ if (decl
+ && TREE_CODE (decl) == VAR_DECL
+ && ! TYPE_P (CP_DECL_CONTEXT (decl)))
+ {
+ error_at (decl_spec_token_start->location,
+ "%qT is not a template type", TREE_TYPE (decl));
+ decl = error_mark_node;
+ }
}
/* Look for a trailing `;' after the declaration. */
Index: testsuite/g++.dg/parse/error50.C
===================================================================
--- testsuite/g++.dg/parse/error50.C (revision 0)
+++ testsuite/g++.dg/parse/error50.C (revision 0)
@@ -0,0 +1,9 @@
+// PR c++/18747
+
+template<> int i; // { dg-error "template" }
+
+struct A
+{
+};
+
+template<> A j; // { dg-error "template" }