Permalink
Browse files

fix Issue 9332 statement is not reachable

  • Loading branch information...
1 parent 5c00c8d commit ea5ee9b2c1173b0f824ab19dcdeb2c409e7d613c @WalterBright WalterBright committed Jan 21, 2013
Showing with 26 additions and 13 deletions.
  1. +14 −12 src/func.c
  2. +1 −1 src/statement.h
  3. +11 −0 test/runnable/warning1.d
View
@@ -1301,6 +1301,20 @@ void FuncDeclaration::semantic3(Scope *sc)
fbody = new CompoundStatement(0, s, fbody);
}
}
+
+ /* Append:
+ * return this;
+ * to function body
+ */
+ if (blockexit & BEfallthru)
+ {
+ Expression *e = new ThisExp(loc);
+ if (cd)
+ e->type = cd->type;
+ Statement *s = new ReturnStatement(loc, e);
+ s = s->semantic(sc2);
+ fbody = new CompoundStatement(loc, fbody, s);
+ }
}
else if (fes)
{ // For foreach(){} body, append a return 0;
@@ -3561,18 +3575,6 @@ void CtorDeclaration::semantic(Scope *sc)
((TypeFunction *)type)->isref = 1;
#endif
- // Append:
- // return this;
- // to the function body
- if (fbody && semanticRun < PASSsemantic)
- {
- Expression *e = new ThisExp(loc);
- if (parent->isClassDeclaration())
- e->type = tret;
- Statement *s = new ReturnStatement(loc, e);
- fbody = new CompoundStatement(loc, fbody, s);
- }
-
FuncDeclaration::semantic(sc);
sc->pop();
View
@@ -611,7 +611,7 @@ struct SwitchErrorStatement : Statement
struct ReturnStatement : Statement
{
Expression *exp;
- int implicit0;
+ bool implicit0; // this is an implicit "return 0;"
ReturnStatement(Loc loc, Expression *exp);
Statement *syntaxCopy();
View
@@ -142,6 +142,17 @@ bool test7232()
return true;
}
+/***************************************************/
+
+struct S9332
+{
+ this(S9332)
+ {
+// while (1) { }
+ assert(0, "unreachable?");
+ }
+}
+
/******************************************/
void main()

0 comments on commit ea5ee9b

Please sign in to comment.