Patchwork C++ PATCH for c++/49669 (ICE on invalid array init)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 6, 2011, 4:29 a.m.
Message ID <4E3CC333.1010300@redhat.com>
Download mbox | patch
Permalink /patch/108757/
State New
Headers show

Comments

Jason Merrill - Aug. 6, 2011, 4:29 a.m.
Just fail more gracefully.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.

Patch

commit a9c72513517e8b5cbf3128cb89994eae59961ade
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Aug 5 16:51:08 2011 -0400

    	PR c++/49669
    	* init.c (perform_member_init): Handle invalid array initializer.

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index d9e475e..4fa627b 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -554,8 +554,10 @@  perform_member_init (tree member, tree init)
 	{
 	  if (init)
 	    {
-	      gcc_assert (TREE_CHAIN (init) == NULL_TREE);
-	      init = TREE_VALUE (init);
+	      if (TREE_CHAIN (init))
+		init = error_mark_node;
+	      else
+		init = TREE_VALUE (init);
 	      if (BRACE_ENCLOSED_INITIALIZER_P (init))
 		init = digest_init (type, init, tf_warning_or_error);
 	    }
diff --git a/gcc/testsuite/g++.dg/init/array28.C b/gcc/testsuite/g++.dg/init/array28.C
new file mode 100644
index 0000000..8cf19ba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/array28.C
@@ -0,0 +1,7 @@ 
+// PR c++/49669
+
+struct Foo { explicit Foo(int) { } };
+struct Goo {
+  Goo() : x(Foo(4), Foo(5)) { } // { dg-error "array" }
+  Foo x[2];
+};