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]

[C++ PATCH] Fix PR c++/6037


Hi!

pushtag doesn't always insert the tag into current binding
level, yet start_enum was expecting this...
Ok to commit?

2002-03-22  Jakub Jelinek  <jakub@redhat.com>

	PR c++/6037
	* decl.c (start_enum): Only set TREE_ADDRESSABLE tag if we actually
	pushed one.  Don't expect it to be added always to current binding
	level.

	* g++.dg/other/enum1.C: New test.

--- gcc/cp/decl.c.jj	Mon Mar 18 23:23:53 2002
+++ gcc/cp/decl.c	Fri Mar 22 15:55:02 2002
@@ -13107,11 +13107,18 @@ start_enum (name)
     {
       enumtype = make_node (ENUMERAL_TYPE);
       pushtag (name, enumtype, 0);
+      if (current_class_type)
+	{
+	  /* pushtag might have pushed the tag into some other binding
+	     level.  */
+	  while (b && (b->tags == NULL || TREE_VALUE (b->tags) != enumtype))
+	    b = b->level_chain;
+	  if (b == NULL)
+	    abort ();
+	  TREE_ADDRESSABLE (b->tags) = 1;
+	}
     }
 
-  if (current_class_type)
-    TREE_ADDRESSABLE (b->tags) = 1;
-
   return enumtype;
 }
 
--- gcc/testsuite/g++.dg/other/enum1.C.jj	Fri Mar 22 16:02:32 2002
+++ gcc/testsuite/g++.dg/other/enum1.C	Fri Mar 22 16:02:29 2002
@@ -0,0 +1,19 @@
+/* PR c++/6037
+   This testcase ICEd because start_enum expected pushtag to insert
+   the tag always into current binding level.  */
+
+struct A
+{
+  ~A () { }
+};
+
+struct B
+{
+  void foo ()
+  {
+    switch (0) { default: ; }
+    A a;
+    enum C { };
+    (void) a;
+  }
+};

	Jakub


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