diff --git a/src/statement.c b/src/statement.c index a5cc0162d261..7bf4737b74cb 100644 --- a/src/statement.c +++ b/src/statement.c @@ -3906,6 +3906,11 @@ Statement *ReturnStatement::semantic(Scope *sc) if (exp && tbret->ty == Tvoid && !implicit0) { + if (exp->type->ty != Tvoid) + { + error("cannot return non-void from void function"); + } + /* Replace: * return exp; * with: @@ -3915,11 +3920,6 @@ Statement *ReturnStatement::semantic(Scope *sc) Statement *s = new ExpStatement(loc, ce); s = s->semantic(sc); - if (exp->type->ty != Tvoid) - { - error("cannot return non-void from void function"); - } - exp = NULL; return new CompoundStatement(loc, s, this); }