Checking current_class_type isn't enough to determine whether we're at class scope; in this testcase it's set, but current_scope() is the member function, so we don't want to mess with the type.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
commit ab4e9d79eae7c11c4dc2e58437f45901c439dca1
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Jul 17 21:01:41 2012 -0400

    	PR c++/53995
    	* decl.c (finish_enum_value_list): Only call
    	insert_late_enum_def_into_classtype_sorted_fields in class scope.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 84b78f6..8a3163a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12392,7 +12392,7 @@ finish_enum_value_list (tree enumtype)
   for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
     TYPE_VALUES (t) = TYPE_VALUES (enumtype);
 
-  if (current_class_type
+  if (at_class_scope_p ()
       && COMPLETE_TYPE_P (current_class_type)
       && UNSCOPED_ENUM_P (enumtype))
     insert_late_enum_def_into_classtype_sorted_fields (enumtype,
diff --git a/gcc/testsuite/g++.dg/parse/enum9.C b/gcc/testsuite/g++.dg/parse/enum9.C
new file mode 100644
index 0000000..559db31
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/enum9.C
@@ -0,0 +1,13 @@
+// PR c++/53995
+
+enum E1 { e };
+void f(E1);
+
+struct A {
+  int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10;
+  void g();
+  void h();
+};
+
+void A::g() { enum E2 { e }; }
+void A::h() { f(e); }

Reply via email to