Skip to content

Commit

Permalink
Fix dtor handling issue introduced by fixing 3825
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Oct 23, 2013
1 parent 325ea56 commit 7c6d516
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/expression.c
Expand Up @@ -14083,7 +14083,6 @@ Expression *BinExp::reorderSettingAAElem(Scope *sc)
{
Identifier *id = Lexer::uniqueId("__aatmp");
VarDeclaration *vd = new VarDeclaration(ie->e1->loc, ie->e1->type, id, new ExpInitializer(ie->e1->loc, ie->e1));
vd->storage_class |= STCref | STCforeach;
Expression *de = new DeclarationExp(ie->e1->loc, vd);

ec = de;
Expand All @@ -14093,7 +14092,8 @@ Expression *BinExp::reorderSettingAAElem(Scope *sc)
{
Identifier *id = Lexer::uniqueId("__aakey");
VarDeclaration *vd = new VarDeclaration(ie->e2->loc, ie->e2->type, id, new ExpInitializer(ie->e2->loc, ie->e2));
vd->storage_class |= STCref | STCforeach;
if (ie->e2->isLvalue())
vd->storage_class |= STCref | STCforeach;
Expression *de = new DeclarationExp(ie->e2->loc, vd);

ec = ec ? new CommaExp(loc, ec, de) : de;
Expand Down
33 changes: 33 additions & 0 deletions test/runnable/testaa2.d
Expand Up @@ -222,6 +222,38 @@ void test3825()
bug8070();
}

void test3825x()
{
static int ctor, cpctor, dtor;

static struct S
{
this(int) { ++ctor; }
this(this) { ++cpctor; }
~this() { ++dtor; }
}

{
auto value = S(1);
assert(ctor==1 && cpctor==0 && dtor==0);

ref getRef(ref S s = value) { return s; }
auto getVal() { return value; }
int[S] aa;

aa[value] = 10;
assert(ctor==1 && cpctor==0 && dtor==0);

aa[getRef()] += 1;
assert(ctor==1 && cpctor==0 && dtor==0);

aa[getVal()] += 1;
assert(ctor==1 && cpctor==1 && dtor==1);
}
assert(ctor==1 && cpctor==1 && dtor==2);
assert(ctor + cpctor == dtor);
}

/************************************************/
// 10106

Expand Down Expand Up @@ -252,6 +284,7 @@ int main()
test1899();
test4523();
test3825();
test3825x();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 7c6d516

Please sign in to comment.