This testcase was aborting when we tried to check ENUM_UNDERLYING_TYPE
on a non-enum. Fixed by checking the tree code first.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit b01c647f6754097ac85e4ca1d7c80c1da8edc660
Author: Jason Merrill <ja...@redhat.com>
Date: Sat Dec 17 09:30:43 2011 -0500
PR c++/51587
* decl.c (start_enum): Avoid using ENUM_UNDERLYING_TYPE on a
non-enum.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index fedc52c..0a43fb8 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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)
diff --git a/gcc/testsuite/g++.dg/parse/enum6.C b/gcc/testsuite/g++.dg/parse/enum6.C
new file mode 100644
index 0000000..e753f51
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/enum6.C
@@ -0,0 +1,8 @@
+// PR c++/51587
+
+namespace N
+{
+ struct X; // { dg-message "previous declaration" }
+}
+
+enum N::X {}; // { dg-error "conflicting declaration" }