Skip to content

Commit ea2916a

Browse files
pfultz2danmar
authored andcommitted
Fix issue 9514: Syntax Error: AST broken, 'for' doesn't have two operands. (#2429)
* Fix issue 9514: Syntax Error: AST broken, 'for' doesn't have two operands. * Fix typo
1 parent 56e17fb commit ea2916a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
883883
compileUnaryOp(tok, state, compileExpression);
884884
else
885885
compileBinOp(tok, state, compileExpression);
886-
if (Token::simpleMatch(tok, "}"))
886+
while (Token::simpleMatch(tok, "}"))
887887
tok = tok->next();
888888
} else break;
889889
}

test/testtokenize.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ class TestTokenizer : public TestFixture {
474474
TEST_CASE(checkLambdas);
475475
TEST_CASE(checkIfCppCast);
476476
TEST_CASE(checkRefQualifiers);
477+
TEST_CASE(checkConditionBlock);
477478

478479
// #9052
479480
TEST_CASE(noCrash1);
@@ -7692,6 +7693,7 @@ class TestTokenizer : public TestFixture {
76927693
ASSERT_EQUALS("Abc({newreturn", testAst("return new A {b(c)};"));
76937694
ASSERT_EQUALS("a{{return", testAst("return{{a}};"));
76947695
ASSERT_EQUALS("a{b{,{return", testAst("return{{a},{b}};"));
7696+
ASSERT_EQUALS("stdvector::", testAst("std::vector<std::vector<int>>{{},{}}"));
76957697
}
76967698

76977699
void astbrackets() { // []
@@ -8178,6 +8180,12 @@ class TestTokenizer : public TestFixture {
81788180

81798181
}
81808182

8183+
void checkConditionBlock() {
8184+
ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n"
8185+
" for (auto b : std::vector<std::vector<int>>{{}, {}}) {}\n"
8186+
"}\n"))
8187+
}
8188+
81818189
void noCrash1() {
81828190
ASSERT_NO_THROW(tokenizeAndStringify(
81838191
"struct A {\n"

0 commit comments

Comments
 (0)