Skip to content

Commit

Permalink
Merge pull request #4551 from 9rnsr/fix14395
Browse files Browse the repository at this point in the history
[REG2.067] Issue 14395 - Typesafe variadic function call collapsed if being used for default value
  • Loading branch information
WalterBright committed Apr 4, 2015
2 parents b99758d + 9982f52 commit e926bec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/expression.c
Expand Up @@ -1501,18 +1501,14 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
a = a->implicitCastTo(sc, tbn);
(*elements)[u] = a;
}
ArrayLiteralExp *ale = new ArrayLiteralExp(loc, elements);
ale->type = tsa;

Identifier *id = Identifier::generateId("__arrayArg");
VarDeclaration *v = new VarDeclaration(loc, tsa, id, new ExpInitializer(loc, ale));
v->storage_class |= STCtemp | STCctfe;
v->semantic(sc);
v->parent = sc->parent;

Expression *de = new DeclarationExp(loc, v);
Expression *ve = new VarExp(loc, v);
arg = Expression::combine(de, ve);
// Bugzilla 14395: Convert to a static array literal, or its slice.
arg = new ArrayLiteralExp(loc, elements);
arg->type = tsa;
if (tb->ty == Tarray)
{
arg = new SliceExp(loc, arg, NULL, NULL);
arg->type = p->type;
}
break;
}
case Tclass:
Expand Down
19 changes: 19 additions & 0 deletions test/runnable/variadic.d
Expand Up @@ -1653,6 +1653,24 @@ void test13508() @safe @nogc
S13508 s = make13508!S13508(5);
}

/***************************************/
// 14395

int v2u14395(uint[1] ar...)
{
return ar[0];
}

void print14395(int size = v2u14395(7))
{
assert(size == 7);
}

void test14395()
{
print14395();
}

/***************************************/
// 10414

Expand Down Expand Up @@ -1787,6 +1805,7 @@ int main()
test7233();
test7263();
test9017();
test14395();
test10414();
test9495();
testCopy();
Expand Down

0 comments on commit e926bec

Please sign in to comment.