Permalink
Browse files

Issue 6470 - postblits not called on arrays of structs

- Call postblits on array slice assign
- Call postblits on array literal elements
  • Loading branch information...
1 parent 2f09427 commit 26aacf0b510d59f572122a55a9a74c071aab889c @9rnsr committed Feb 2, 2012
Showing with 55 additions and 2 deletions.
  1. +1 −1 src/e2ir.c
  2. +22 −1 src/expression.c
  3. +32 −0 test/runnable/sdtor.d
View
@@ -2753,7 +2753,7 @@ elem *AssignExp::toElem(IRState *irs)
/* Determine if we need to do postblit
*/
int postblit = 0;
- if (needsPostblit(t1))
+ if (needsPostblit(t1->nextOf()))
postblit = 1;
assert(e2->type->ty != Tpointer);
View
@@ -770,6 +770,18 @@ void valueNoDtor(Expression *e)
#if DMDV2
Expression *callCpCtor(Loc loc, Scope *sc, Expression *e, int noscope)
{
+ if (e->op == TOKarrayliteral)
+ {
+ ArrayLiteralExp *ae = (ArrayLiteralExp *)e;
+ for (size_t i = 0; i < ae->elements->dim; i++)
+ {
+ ae->elements->tdata()[i] =
+ callCpCtor(loc, sc, ae->elements->tdata()[i], noscope);
+ }
+ e = ae->semantic(sc);
+ return e;
+ }
+
Type *tb = e->type->toBasetype();
Type *tv = tb;
while (tv->ty == Tsarray)
@@ -1082,7 +1094,11 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
}
Type *tb = arg->type->toBasetype();
- if (tb->ty == Tsarray)
+ if (arg->op == TOKarrayliteral)
+ {
+ arg = callCpCtor(loc, sc, arg, 1);
+ }
+ else if (tb->ty == Tsarray)
{
#if !SARRAYVALUE
// Convert static arrays to pointers
@@ -10462,6 +10478,11 @@ Expression *AssignExp::semantic(Scope *sc)
if (!e2->rvalue())
return new ErrorExp();
+ if (e2->op == TOKarrayliteral)
+ {
+ e2 = callCpCtor(loc, sc, e2, 1);
+ }
+
if (e1->op == TOKarraylength)
{
// e1 is not an lvalue, but we let code generator handle it
View
@@ -1878,6 +1878,37 @@ void test6177()
/**********************************/
+// 6470
+
+struct S6470
+{
+ static int spblit;
+
+ this(this){ ++spblit; }
+}
+
+void test6470()
+{
+ S6470[] a1;
+ S6470[] a2;
+ a1.length = 3;
+ a2.length = 3;
+ a1[] = a2[];
+ assert(S6470.spblit == 3);
+
+ S6470 s;
+
+ S6470[] a3;
+ a3.length = 3;
+ a3 = [s, s, s];
+ assert(S6470.spblit == 6);
+
+ void func(S6470[] a){}
+ func([s, s, s]);
+ assert(S6470.spblit == 9);
+}
+
+/**********************************/
// 6636
struct S6636
@@ -2025,6 +2056,7 @@ int main()
test60();
test4316();
test6177();
+ test6470();
test6636();
test6637();
test7353();

0 comments on commit 26aacf0

Please sign in to comment.