re PR c++/47144 (Doesn't reject attempt to define type in template argument; results...
authorJason Merrill <jason@redhat.com>
Fri, 11 Mar 2011 22:47:59 +0000 (17:47 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 11 Mar 2011 22:47:59 +0000 (17:47 -0500)
PR c++/47144
* parser.c (cp_parser_template_type_arg): Set
type_definition_forbidden_message.

From-SVN: r170888

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/no-type-defn1.C [new file with mode: 0644]

index 29156efc4e3c5ef5f1413a3d7cbda77de1f7a44b..64281fd684e80352c8c53ddb7d0d838b49ffd6c0 100644 (file)
@@ -1,5 +1,9 @@
 2011-03-11  Jason Merrill  <jason@redhat.com>
 
+       PR c++/47144
+       * parser.c (cp_parser_template_type_arg): Set
+       type_definition_forbidden_message.
+
        PR c++/47808
        * decl.c (compute_array_index_type): Discard folding
        if it didn't produce a constant.
index 7e9b286c0ae50bd0fe34646054e4a8caf7a0fac1..4260f6d135a9f3eb5c3c0f2b15471cab4dc5bbd2 100644 (file)
@@ -15685,7 +15685,13 @@ static tree cp_parser_type_id (cp_parser *parser)
 
 static tree cp_parser_template_type_arg (cp_parser *parser)
 {
-  return cp_parser_type_id_1 (parser, true, false);
+  tree r;
+  const char *saved_message = parser->type_definition_forbidden_message;
+  parser->type_definition_forbidden_message
+    = G_("types may not be defined in template arguments");
+  r = cp_parser_type_id_1 (parser, true, false);
+  parser->type_definition_forbidden_message = saved_message;
+  return r;
 }
 
 static tree cp_parser_trailing_type_id (cp_parser *parser)
index 6734535f7bbb1ac73883609fd219e3ee266f399d..5ee1fcd933559242d7acc7a19810cb33b67a0609 100644 (file)
@@ -1,5 +1,7 @@
 2011-03-11  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/parse/no-type-defn1.C: New.
+
        * g++.dg/ext/attrib40.C: New.
 
        * g++.dg/cpp0x/regress/array1.C: New.
diff --git a/gcc/testsuite/g++.dg/parse/no-type-defn1.C b/gcc/testsuite/g++.dg/parse/no-type-defn1.C
new file mode 100644 (file)
index 0000000..9e89957
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/47144
+
+template<typename> struct A { };
+A< struct B { }* >::SomeNonSense // { dg-error "types may not be defined" }
+int y;