Patchwork C++ PATCH for c++/51587 (ICE with struct/enum conflict)

login
register
mail settings
Submitter Jason Merrill
Date Dec. 17, 2011, 7:26 p.m.
Message ID <4EECECD8.8060306@redhat.com>
Download mbox | patch
Permalink /patch/132019/
State New
Headers show

Comments

Jason Merrill - Dec. 17, 2011, 7:26 p.m.
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.
Fabien Chêne - Dec. 17, 2011, 11:47 p.m.
2011/12/17 Jason Merrill <jason@redhat.com>:
> This testcase was aborting when we tried to check ENUM_UNDERLYING_TYPE on a
> non-enum.  Fixed by checking the tree code first.

Ahem ... thank you !

Patch

commit b01c647f6754097ac85e4ca1d7c80c1da8edc660
Author: Jason Merrill <jason@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" }