Comments
Patch
commit 5e42b54f626d5796ecb21ea2c78a7be2699a4c0a
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jun 30 17:48:10 2011 -0400
PR c++/49355
* tree.c (stabilize_init): Handle aggregate initialization.
@@ -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. */
new file mode 100644
@@ -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({""});
+}