Skip to content

Commit

Permalink
Merge pull request #986 from 9rnsr/fix3574
Browse files Browse the repository at this point in the history
Issue 3574 - post-condition in void main() is not evaluated if there is no return statement
  • Loading branch information
WalterBright committed Jun 11, 2012
2 parents 0c6353c + 2b05220 commit 48d389b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/func.c
Expand Up @@ -1317,15 +1317,7 @@ void FuncDeclaration::semantic3(Scope *sc)

int offend = blockexit & BEfallthru;
#endif
if (type->nextOf()->ty == Tvoid)
{
if (offend && isMain())
{ // Add a return 0; statement
Statement *s = new ReturnStatement(0, new IntegerExp(0));
fbody = new CompoundStatement(0, fbody, s);
}
}
else
if (type->nextOf()->ty != Tvoid)
{
if (offend)
{ Expression *e;
Expand Down Expand Up @@ -1551,6 +1543,11 @@ void FuncDeclaration::semantic3(Scope *sc)
a->push(s);
}
}
if (isMain() && type->nextOf()->ty == Tvoid)
{ // Add a return 0; statement
Statement *s = new ReturnStatement(0, new IntegerExp(0));
a->push(s);
}

fbody = new CompoundStatement(0, a);
#if DMDV2
Expand Down
13 changes: 13 additions & 0 deletions test/runnable/test3574a.d
@@ -0,0 +1,13 @@
int g = 0;
static ~this() { assert(g == 100); }

void main()
out
{
g = 100;
}
body
{
return;
// expected return code == 0
}
13 changes: 13 additions & 0 deletions test/runnable/test3574b.d
@@ -0,0 +1,13 @@
int g = 0;
static ~this() { assert(g == 100); }

void main()
out
{
g = 100;
}
body
{
//return;
// expected return code == 0
}
13 changes: 13 additions & 0 deletions test/runnable/test3574c.d
@@ -0,0 +1,13 @@
//int g = 0;
//static ~this() { assert(g == 100); }

void main()
//out
//{
// g = 100;
//}
//body
{
return;
// expected return code == 0
}
13 changes: 13 additions & 0 deletions test/runnable/test3574d.d
@@ -0,0 +1,13 @@
//int g = 0;
//static ~this() { assert(g == 100); }

void main()
//out
//{
// g = 100;
//}
//body
{
//return;
// expected return code == 0
}

0 comments on commit 48d389b

Please sign in to comment.