Skip to content

Commit

Permalink
fix Issue 13503 - Bad code with -inline, varargs and auto return
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Sep 22, 2014
1 parent 3c5d1cd commit ff6e7d6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/func.c
Expand Up @@ -1639,8 +1639,9 @@ void FuncDeclaration::semantic3(Scope *sc)
{
if (storage_class & STCauto)
storage_class &= ~STCauto;
nrvo_can = 0;
}
if (retStyle(f) != RETstack)
nrvo_can = 0;

if (isStaticCtorDeclaration())
{
Expand Down
4 changes: 2 additions & 2 deletions src/inline.c
Expand Up @@ -1355,7 +1355,7 @@ class InlineScanVisitor : public Visitor
if (e->op == TOKconstruct && e->e2->op == TOKcall)
{
CallExp *ce = (CallExp *)e->e2;
if (ce->f && ce->f->nrvo_var) // NRVO
if (ce->f && ce->f->nrvo_can && ce->f->nrvo_var) // NRVO
{
if (e->e1->op == TOKvar)
{
Expand Down Expand Up @@ -1774,7 +1774,7 @@ static Expression *expandInline(FuncDeclaration *fd, FuncDeclaration *parent,
TypeFunction *tf = (TypeFunction*)fd->type;

#if LOG || CANINLINE_LOG
printf("FuncDeclaration::expandInline('%s')\n", toChars());
printf("FuncDeclaration::expandInline('%s')\n", fd->toChars());
#endif

memset(&ids, 0, sizeof(ids));
Expand Down
27 changes: 27 additions & 0 deletions test/runnable/inline.d
Expand Up @@ -530,6 +530,32 @@ class Foo12080
}
}

/**********************************/
// 13503

void f13503a(string[] s...)
{
assert(s[0] == "Cheese");
}

auto f13503b(string arg)
{
string result = arg;
return result;
}

string f13503c(string arg)
{
string result = arg;
return result;
}

void test13503()
{
f13503a(f13503b("Cheese"));
f13503a(f13503c("Cheese"));
}

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

int main()
Expand All @@ -551,6 +577,7 @@ int main()
test11224();
test11322();
test11394();
test13503();

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

0 comments on commit ff6e7d6

Please sign in to comment.