Patchwork C++ PATCH for c++/46289 (ICE on invalid mem-init-list in constexpr ctor)

login
register
mail settings
Submitter Jason Merrill
Date Nov. 3, 2010, 7:01 p.m.
Message ID <4CD1B18A.6070000@redhat.com>
Download mbox | patch
Permalink /patch/70051/
State New
Headers show

Comments

Jason Merrill - Nov. 3, 2010, 7:01 p.m.
The testcase in the PR ought to be valid, but even on an invalid 
initializer we shouldn't ICE.  This patch just fixes the ICE.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit 52121dc67cca2e2ac46b8d7389bb375f635afb95
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 3 11:57:38 2010 -0400

    	PR c++/46289
    	* semantics.c (build_constexpr_constructor_member_initializers):
    	Avoid ICE on error.

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 3215410..562fab1 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5507,10 +5507,9 @@  build_constexpr_constructor_member_initializers (tree type, tree body)
     body = BIND_EXPR_BODY (body);
   if (TREE_CODE (body) == CLEANUP_POINT_EXPR)
     ok = build_data_member_initialization (body, &vec);
-  else
+  else if (TREE_CODE (body) == STATEMENT_LIST)
     {
       tree_stmt_iterator i;
-      gcc_assert (TREE_CODE (body) == STATEMENT_LIST);
       for (i = tsi_start (body); !tsi_end_p (i); tsi_next (&i))
 	{
 	  ok = build_data_member_initialization (tsi_stmt (i), &vec);
@@ -5518,6 +5517,8 @@  build_constexpr_constructor_member_initializers (tree type, tree body)
 	    break;
 	}
     }
+  else
+    gcc_assert (errorcount > 0);
   if (ok)
     return build_constructor (type, vec);
   else
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice3.C
new file mode 100644
index 0000000..23903bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice3.C
@@ -0,0 +1,13 @@ 
+// PR c++/46289
+// { dg-options -std=c++0x }
+
+struct A
+{
+  int i;
+};
+
+struct B
+{
+  A a;
+  constexpr B(): a({1,2}) { }	// { dg-error "" }
+};