This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/58611 (ICE with invalid constexpr array)


Calling finish_compound_literal in this case ends up trying to reshape an initializer that has already been digested, and removing the call doesn't seem to break anything.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 6f94e657ce04fd32cac5e616e9ca675c40e3fab5
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jul 13 13:53:24 2014 -0400

    	PR c++/58611
    	* decl.c (check_initializer): Don't finish_compound_literal
    	on erroneous constexpr init.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 8f829d0..9d3fbb2 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5812,11 +5812,8 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
 	      /* Declared constexpr, but no suitable initializer; massage
 		 init appropriately so we can pass it into store_init_value
 		 for the error.  */
-	      if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
-		init = finish_compound_literal (type, init,
-						tf_warning_or_error);
-	      else if (CLASS_TYPE_P (type)
-		       && (!init || TREE_CODE (init) == TREE_LIST))
+	      if (CLASS_TYPE_P (type)
+		  && (!init || TREE_CODE (init) == TREE_LIST))
 		{
 		  init = build_functional_cast (type, init, tf_none);
 		  if (TREE_CODE (init) == TARGET_EXPR)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array6.C
new file mode 100644
index 0000000..16eacdd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array6.C
@@ -0,0 +1,15 @@
+// PR c++/58611
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  int i;
+  constexpr A() {}		// { dg-error "A::i" }
+};
+
+struct B
+{
+  A a;
+};
+
+constexpr B b[] = { {} };	// { dg-error "A::A" }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]