re PR c++/49355 (new T({""}) crashes G++ when struct T { std::string foobar };)
authorJason Merrill <jason@redhat.com>
Fri, 1 Jul 2011 00:03:34 +0000 (20:03 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 1 Jul 2011 00:03:34 +0000 (20:03 -0400)
PR c++/49355
* tree.c (stabilize_init): Handle aggregate initialization.

From-SVN: r175736

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist54.C [new file with mode: 0644]

index 42c21fe2150515b60fdf86e15c6e9d4e4883cc18..70b6f779bf6c7149394a561e9c5cb6155488a9b8 100644 (file)
@@ -1,5 +1,8 @@
 2011-06-30  Jason Merrill  <jason@redhat.com>
 
+       PR c++/49355
+       * tree.c (stabilize_init): Handle aggregate initialization.
+
        PR c++/48481
        * name-lookup.c (struct arg_lookup): Add fn_set.
        (add_function): Check it.
index c50751f7ebb35e479d32359e42b9068d5c957260..678c7ef9bf1c6ad347c060035cca60bfd9db79ff 100644 (file)
@@ -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.  */
index 66e980ac7e469a748311807b6f5e0b18c4d3e726..ed34b5f3c10e6e877118fb6c972df810e1c66d28 100644 (file)
@@ -1,3 +1,8 @@
+2011-06-30  Jason Merrill  <jason@redhat.com>
+
+       PR c++/49355
+       * g++.dg/cpp0x/initlist54.C: New.
+
 2011-06-30  Martin Jambor  <mjambor@suse.cz>
 
        * gcc.dg/tree-ssa/sra-12.c: New test.
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist54.C b/gcc/testsuite/g++.dg/cpp0x/initlist54.C
new file mode 100644 (file)
index 0000000..cdb2961
--- /dev/null
@@ -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({""});
+}