Skip to content

Commit

Permalink
Merge pull request #3737 from 9rnsr/fix11066
Browse files Browse the repository at this point in the history
Issue 11066 - Spurious warning 'statement is not reachable' with -profile
  • Loading branch information
WalterBright authored and 9rnsr committed Jul 16, 2014
1 parent a694824 commit d30cd00
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
51 changes: 25 additions & 26 deletions src/func.c
Expand Up @@ -1718,9 +1718,12 @@ void FuncDeclaration::semantic3(Scope *sc)
//printf("callSuper = x%x\n", sc2->callSuper);

// For foreach(){} body, append a return 0;
Expression *e = new IntegerExp(0);
Statement *s = new ReturnStatement(Loc(), e);
fbody = new CompoundStatement(Loc(), fbody, s);
if (blockexit & BEfallthru)
{
Expression *e = new IntegerExp(0);
Statement *s = new ReturnStatement(Loc(), e);
fbody = new CompoundStatement(Loc(), fbody, s);
}
assert(!returnLabel);
}
else if (!hasReturnExp && type->nextOf()->ty != Tvoid)
Expand All @@ -1742,32 +1745,28 @@ void FuncDeclaration::semantic3(Scope *sc)
f->isnothrow = !(blockexit & BEthrow);
}

int offend = blockexit & BEfallthru;
if (type->nextOf()->ty != Tvoid)
if ((blockexit & BEfallthru) && type->nextOf()->ty != Tvoid)
{
if (offend)
Expression *e;
error("no return exp; or assert(0); at end of function");
if (global.params.useAssert &&
!global.params.useInline)
{
Expression *e;
error("no return exp; or assert(0); at end of function");
if (global.params.useAssert &&
!global.params.useInline)
{
/* Add an assert(0, msg); where the missing return
* should be.
*/
e = new AssertExp(
endloc,
new IntegerExp(0),
new StringExp(loc, (char *)"missing return expression")
);
}
else
e = new HaltExp(endloc);
e = new CommaExp(Loc(), e, type->nextOf()->defaultInit());
e = e->semantic(sc2);
Statement *s = new ExpStatement(Loc(), e);
fbody = new CompoundStatement(Loc(), fbody, s);
/* Add an assert(0, msg); where the missing return
* should be.
*/
e = new AssertExp(
endloc,
new IntegerExp(0),
new StringExp(loc, (char *)"missing return expression")
);
}
else
e = new HaltExp(endloc);
e = new CommaExp(Loc(), e, type->nextOf()->defaultInit());
e = e->semantic(sc2);
Statement *s = new ExpStatement(Loc(), e);
fbody = new CompoundStatement(Loc(), fbody, s);
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/compilable/diag11066.d
@@ -0,0 +1,13 @@
// REQUIRED_ARGS: -w -profile
/*
TEST_OUTPUT:
---
---
*/

void main()
{
string s;
foreach (dchar c; s) // affected by dchar
return;
}

0 comments on commit d30cd00

Please sign in to comment.