This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR c++/18731: typedef-names in class heads


When parsing a class head with a nested-name-specifier we
crash since GCC 3.3 if it contains a template parameter like in

  template<typename T> struct T::A {};

or in

  template<typename T> struct A { struct T::B {}; };

In addition we accept code like the following

  struct A { struct B; typedef B C; };
  struct A::C {};

although only A::B should be accepted and not A::C.

This is because we fail to reject typedef-names in class heads.
The following patch fixes that.

Bootstrapped and regtested on mainline and 3.4 branch (i686-pc-linux-gnu).
(The patch for the 3.4 branch of course uses `%D' instead of %qD
in the format string of the error message.)

Ok to commit to mainline and 3.4 branch?


Regards,
Volker



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.


Index: parser.c
===================================================================
RCS file: /home/reichelt/GCC/CVS/gcc-cvs/gcc/gcc/cp/parser.c,v
retrieving revision 1.292
diff -u -p -r1.292 parser.c
--- parser.c	9 Dec 2004 20:47:35 -0000	1.292
+++ parser.c	10 Dec 2004 13:00:13 -0000
@@ -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
===================================================================


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 18:34:25.737672000 +0100
+++ struct-1.C  2004-12-09 18:33:47.000000000 +0100
@@ -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" }
===================================================================
--- -   2004-12-09 18:34:49.626620000 +0100
+++ struct-2.C  2004-12-09 18:33:49.000000000 +0100
@@ -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" }
+};
===================================================================
--- -   2004-12-09 18:35:07.236547000 +0100
+++ struct-3.C  2004-12-09 18:33:39.000000000 +0100
@@ -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" }
===================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]