PR d/120096
gcc/d/ChangeLog:
* expr.cc (ExprVisitor::visit (ArrayLiteralExp *)): Include saved side
effects in expression result.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr120096.d: New test.
/* Array literal for a `scope' dynamic array. */
gcc_assert (tb->ty == TY::Tarray);
ctor = force_target_expr (ctor);
- this->result_ = d_array_value (type, size_int (e->elements->length),
- build_address (ctor));
+ ctor = d_array_value (type, size_int (e->elements->length),
+ build_address (force_target_expr (ctor)));
+ this->result_ = compound_expr (saved_elems, ctor);
}
else
{
--- /dev/null
+// { dg-do run }
+// { dg-additional-options "-fpreview=dip1000" }
+// { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
+struct S
+{
+ this(int p) nothrow @nogc @safe
+ { f = p; }
+ int f;
+}
+
+int main() nothrow @nogc @safe
+{
+ scope S[] sa = [S(1), S(2)];
+
+ assert(sa[0].f == 1);
+ assert(sa[1].f == 2);
+ return 0;
+}