From: Wolfgang Bumiller Date: Tue, 20 Jan 2015 19:55:27 +0000 (+0100) Subject: fix for loops X-Git-Tag: xonotic-v0.8.2~21 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5c64437189af4a9ee976ea86629d3aa35f078d3e;p=xonotic%2Fgmqcc.git fix for loops --- diff --git a/parser.cpp b/parser.cpp index 75f9312..72f5479 100644 --- a/parser.cpp +++ b/parser.cpp @@ -2480,18 +2480,20 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou initexpr = parse_expression_leave(parser, false, false, false); if (!initexpr) goto onerr; - /* move on to condition */ if (parser->tok != ';') { parseerror(parser, "expected semicolon after for-loop initializer"); goto onerr; } - if (!parser_next(parser)) { parseerror(parser, "expected for-loop condition"); goto onerr; } } + else if (!parser_next(parser)) { + parseerror(parser, "expected for-loop condition"); + goto onerr; + } /* parse the condition */ if (parser->tok != ';') { @@ -5685,6 +5687,8 @@ skipvar: ast_delete(basetype); for (auto &it : parser->gotos) parseerror(parser, "undefined label: `%s`", it->name); + parser->gotos.clear(); + parser->labels.clear(); return true; } else { ast_expression *cexp; diff --git a/tests/forloop.qc b/tests/forloop.qc new file mode 100644 index 0000000..17512bd --- /dev/null +++ b/tests/forloop.qc @@ -0,0 +1,13 @@ +void main() { + float j; + for (j = 0; j < 2; ++j) + print("+"); + + for (float i = 0; i < 5; ++i) + print("*"); + + for (;;) { + print("\n"); + break; + } +} diff --git a/tests/forloop.tmpl b/tests/forloop.tmpl new file mode 100644 index 0000000..2718dfc --- /dev/null +++ b/tests/forloop.tmpl @@ -0,0 +1,5 @@ +I: forloop.qc +D: test for loops +T: -execute +C: -std=gmqcc +M: ++*****