re PR c++/51587 (ICE with struct vs. enum clash)
authorJason Merrill <jason@redhat.com>
Sat, 17 Dec 2011 19:26:46 +0000 (14:26 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 17 Dec 2011 19:26:46 +0000 (14:26 -0500)
PR c++/51587
* decl.c (start_enum): Avoid using ENUM_UNDERLYING_TYPE on a
non-enum.

From-SVN: r182441

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/enum6.C [new file with mode: 0644]

index 6ed8a03..a63aa16 100644 (file)
@@ -1,3 +1,9 @@
+2011-12-17  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51587
+       * decl.c (start_enum): Avoid using ENUM_UNDERLYING_TYPE on a
+       non-enum.
+
 2011-12-16  Jason Merrill  <jason@redhat.com>
 
        PR c++/51416
index fedc52c..0a43fb8 100644 (file)
@@ -12069,6 +12069,7 @@ start_enum (tree name, tree enumtype, tree underlying_type,
       /* Do not push the decl more than once, unless we need to
         compare underlying types at instantiation time */
       if (!enumtype
+         || TREE_CODE (enumtype) != ENUMERAL_TYPE
          || (underlying_type
              && dependent_type_p (underlying_type))
          || (ENUM_UNDERLYING_TYPE (enumtype)
index 660ff9b..71194f5 100644 (file)
@@ -1,3 +1,8 @@
+2011-12-17  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51587
+       * g++.dg/parse/enum6.C: New.
+
 2011-12-17  Tom de Vries  <tom@codesourcery.com>
 
        PR tree-optimization/51491
diff --git a/gcc/testsuite/g++.dg/parse/enum6.C b/gcc/testsuite/g++.dg/parse/enum6.C
new file mode 100644 (file)
index 0000000..e753f51
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/51587
+
+namespace N
+{
+  struct X;                    // { dg-message "previous declaration" }
+}
+
+enum N::X {};                  // { dg-error "conflicting declaration" }