commit f1a7cdfc760884b87fc888e70c34f3268d77aeac
Author: Jason Merrill <jason@redhat.com>
Date: Tue Oct 25 10:37:47 2011 -0400
PR c++/49996
* tree.c (stabilize_init): Stabilize scalar elements of a
CONSTRUCTOR, too.
@@ -3345,11 +3345,20 @@ stabilize_init (tree init, tree *initp)
/* Aggregate initialization: stabilize each of the field
initializers. */
unsigned i;
- tree value;
+ constructor_elt *ce;
bool good = true;
- FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), i, value)
- if (!stabilize_init (value, initp))
- good = false;
+ VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (t);
+ for (i = 0; VEC_iterate (constructor_elt, v, i, ce); ++i)
+ {
+ tree type = TREE_TYPE (ce->value);
+ tree subinit;
+ if (TREE_CODE (type) == REFERENCE_TYPE
+ || SCALAR_TYPE_P (type))
+ ce->value = stabilize_expr (ce->value, &subinit);
+ else if (!stabilize_init (ce->value, &subinit))
+ good = false;
+ *initp = add_stmt_to_compound (*initp, subinit);
+ }
return good;
}
new file mode 100644
@@ -0,0 +1,18 @@
+// PR c++/49996
+// { dg-options -std=c++0x }
+
+struct A
+{
+ ~A()
+ { }
+};
+
+struct B
+{
+ const A& ref;
+};
+
+int main()
+{
+ B* p = new B{A()};
+}