OSDN Git Service

PR c++/49355
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Jul 2011 00:03:34 +0000 (00:03 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Jul 2011 00:03:34 +0000 (00:03 +0000)
* tree.c (stabilize_init): Handle aggregate initialization.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175736 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 42c21fe..70b6f77 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 c50751f..678c7ef 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 66e980a..ed34b5f 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({""});
+}