Skip to content

Commit

Permalink
fix Issue 14321 - Unnecessary destructor call with and AA's
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Mar 24, 2015
1 parent 13af280 commit 751155f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/expression.c
Expand Up @@ -1280,6 +1280,14 @@ Expression *valueNoDtor(Expression *e)
}
}
}
else if (e->op == TOKvar)
{
VarDeclaration *vtmp = ((VarExp *)e)->var->isVarDeclaration();
if (vtmp && vtmp->storage_class & STCrvalue)
{
vtmp->noscope = 1;
}
}
return e;
}

Expand Down
38 changes: 38 additions & 0 deletions test/runnable/testaa.d
Expand Up @@ -1289,6 +1289,43 @@ void test14144()
assert("wat" in x);
}

/************************************************/
// 14321

void test14321()
{
struct Foo
{
static string op;

this(int id) { op ~= "c"; }
this(this) { op ~= "p"; }
~this() { op ~= "d"; }
}
Foo[string] foos;
assert(Foo.op == "");
foos["test"] = Foo(42); // initialization
assert(Foo.op == "c");
foos["test"] = Foo(42); // assignment
assert(Foo.op == "ccd");

struct Bar
{
static string op;

int id;
//this(int id) { op ~= "c"; }
this(this) { op ~= "p"; }
~this() { op ~= "d"; }
}
Bar[string] bars;
assert(Bar.op == "");
bars["test"] = Bar(42); // initialization
assert(Bar.op == "");
bars["test"] = Bar(42); // assignment
assert(Bar.op == "d");
}

/************************************************/

int main()
Expand Down Expand Up @@ -1339,6 +1376,7 @@ int main()
test11359();
test11730();
test14089();
test14321();

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

0 comments on commit 751155f

Please sign in to comment.