re PR c++/18731 (ICE on invalid template declaration)
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>
Fri, 10 Dec 2004 16:04:22 +0000 (16:04 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Fri, 10 Dec 2004 16:04:22 +0000 (16:04 +0000)
PR c++/18731
* parser.c (cp_parser_class_head): Reject typedef-name in class head.

* g++.dg/parser/struct-1.C: New test.
* g++.dg/parser/struct-2.C: New test.
* g++.dg/parser/struct-3.C: New test.

From-SVN: r91993

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/struct-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/struct-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/struct-3.C [new file with mode: 0644]

index 83fac5a9f0cba418106d649b9245cd324f45b488..1abbc26e039df6ffbdd6e42da448cab8ae87f21b 100644 (file)
@@ -1,3 +1,8 @@
+2004-12-10  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       PR c++/18731
+       * parser.c (cp_parser_class_head): Reject typedef-name in class head.
+
 2004-12-09  Matt Austern  <austern@apple.com>
 
        PR c++/18514
index 64f468d4a2b0d03acdae986358863c0137ddd758..b728ad1d1b61ef91e3cb1572d95addf2cfe78c22 100644 (file)
@@ -12620,6 +12620,15 @@ cp_parser_class_head (cp_parser* parser,
   else if (nested_name_specifier)
     {
       tree scope;
+
+      /* Reject typedef-names in class heads.  */
+      if (!DECL_IMPLICIT_TYPEDEF_P (type))
+       {
+         error ("invalid class name in declaration of %qD", type);
+         type = NULL_TREE;
+         goto done;
+       }
+
       /* Figure out in what scope the declaration is being placed.  */
       scope = current_scope ();
       /* If that scope does not contain the scope in which the
index 896b5c755f96ed47798e064814cd03a8226831d4..08e72216bebd64d3e6bacfe4e42dd1dac1382543 100644 (file)
@@ -1,3 +1,10 @@
+2004-12-10  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       PR c++/18731
+       * g++.dg/parser/struct-1.C: New test.
+       * g++.dg/parser/struct-2.C: New test.
+       * g++.dg/parser/struct-3.C: New test.
+
 2004-12-09  Richard Henderson  <rth@redhat.com>
 
        * gcc.dg/loop-3.c: Don't use i386 tuning for amd64.
diff --git a/gcc/testsuite/g++.dg/parse/struct-1.C b/gcc/testsuite/g++.dg/parse/struct-1.C
new file mode 100644 (file)
index 0000000..6e0d93a
--- /dev/null
@@ -0,0 +1,4 @@
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+// PR c++/18731
+
+template<typename T> struct T::A {}; // { dg-error "invalid class name" }
diff --git a/gcc/testsuite/g++.dg/parse/struct-2.C b/gcc/testsuite/g++.dg/parse/struct-2.C
new file mode 100644 (file)
index 0000000..b63045b
--- /dev/null
@@ -0,0 +1,7 @@
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+// PR c++/18731
+
+template<typename T> struct A
+{
+    struct T::B {}; // { dg-error "invalid class name" }
+};
diff --git a/gcc/testsuite/g++.dg/parse/struct-3.C b/gcc/testsuite/g++.dg/parse/struct-3.C
new file mode 100644 (file)
index 0000000..8e73ce4
--- /dev/null
@@ -0,0 +1,10 @@
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+// PR c++/18731
+
+struct A
+{
+    struct B;
+    typedef B C;
+};
+
+struct A::C {}; // { dg-error "invalid class name" }