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 for c++/70627 (ICE with opaque enum)


Here the redeclaration of H changed the underlying type from a typedef to a non-typedef, leading to confusion in the back end. We shouldn't change the underlying type from redeclarations.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit bfabb2dff84a409cf856cda7959ff4395f073d8b
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 13 11:43:59 2016 -0400

    	PR c++/70627
    
    	* decl.c (start_enum): Don't change an existing ENUM_UNDERLYING_TYPE.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 8867b43..0326900 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13257,7 +13257,10 @@ start_enum (tree name, tree enumtype, tree underlying_type,
 
   if (underlying_type)
     {
-      if (CP_INTEGRAL_TYPE_P (underlying_type))
+      if (ENUM_UNDERLYING_TYPE (enumtype))
+	/* We already checked that it matches, don't change it to a different
+	   typedef variant.  */;
+      else if (CP_INTEGRAL_TYPE_P (underlying_type))
         {
 	  copy_type_enum (enumtype, underlying_type);
           ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum_base3.C b/gcc/testsuite/g++.dg/cpp0x/enum_base3.C
new file mode 100644
index 0000000..3cb2d6d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum_base3.C
@@ -0,0 +1,29 @@
+// PR c++/70627
+// { dg-do compile { target c++11 } }
+
+struct D;
+struct A
+{
+  D *operator->();
+};
+struct B
+{
+  template <typename... T> void foo (T &&...) {}
+};
+typedef unsigned char G;
+enum class H : G;
+struct C
+{
+};
+struct D : C
+{
+  B foo () const { B a; a.foo (d); }
+  H d;
+};
+struct F : C
+{
+  void foo ();
+  A f;
+};
+enum class H : unsigned char;
+void F::foo () { B b = f->foo (); }

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