The problem here was that stabilize_init called from build_new_1 wasn't doing anything to stabilize the elements of a CONSTRUCTOR, so the allocator argument wasn't preevaluated, and due to the cleanup for the data pointer its cleanup wasn't associated with the CLEANUP_POINT_EXPR, leading to a crash.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 5e42b54f626d5796ecb21ea2c78a7be2699a4c0a
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Jun 30 17:48:10 2011 -0400

    	PR c++/49355
    	* tree.c (stabilize_init): Handle aggregate initialization.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index c50751f..678c7ef 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -3291,10 +3291,18 @@ stabilize_init (tree init, tree *initp)
     t = TARGET_EXPR_INITIAL (t);
   if (TREE_CODE (t) == COMPOUND_EXPR)
     t = expr_last (t);
-  if (TREE_CODE (t) == CONSTRUCTOR
-      && EMPTY_CONSTRUCTOR_P (t))
-    /* Default-initialization.  */
-    return true;
+  if (TREE_CODE (t) == CONSTRUCTOR)
+    {
+      /* Aggregate initialization: stabilize each of the field
+	 initializers.  */
+      unsigned i;
+      tree value;
+      bool good = true;
+      FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), i, value)
+	if (!stabilize_init (value, initp))
+	  good = false;
+      return good;
+    }
 
   /* If the initializer is a COND_EXPR, we can't preevaluate
      anything.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist54.C b/gcc/testsuite/g++.dg/cpp0x/initlist54.C
new file mode 100644
index 0000000..cdb2961
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist54.C
@@ -0,0 +1,13 @@
+// PR c++/49355
+// { dg-options -std=c++0x }
+
+#include <string>
+
+struct T {
+  std::string foobar;
+};
+
+int main()
+{
+  T* x = new T({""});
+}

Reply via email to