Skip to content

Commit

Permalink
Fix Issue 3022 - scope x = new Foo; does not allocate on stack if Foo…
Browse files Browse the repository at this point in the history
… has allocator

If new only has one argument, then it must be the size.
  • Loading branch information
yebblies committed Sep 9, 2014
1 parent 3cf215f commit e7242b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/declaration.c
Expand Up @@ -1461,7 +1461,7 @@ void VarDeclaration::semantic(Scope *sc)
{
// See if initializer is a NewExp that can be allocated on the stack
NewExp *ne = (NewExp *)ex;
if (!(ne->newargs && ne->newargs->dim) && type->toBasetype()->ty == Tclass)
if (!(ne->newargs && ne->newargs->dim > 1) && type->toBasetype()->ty == Tclass)
{
ne->onstack = 1;
onstack = 1;
Expand Down
16 changes: 16 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -2515,6 +2515,21 @@ void test124() {

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

void test3022()
{
static class Foo3022
{
new(size_t)
{
assert(0);
}
}

scope x = new Foo3022;
}

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

void doNothing() {}

void bug5071(short d, ref short c) {
Expand Down Expand Up @@ -7286,6 +7301,7 @@ int main()
test6733();
test6813();
test6859();
test3022();
test6910();
test6902();
test6330();
Expand Down

0 comments on commit e7242b6

Please sign in to comment.