From ea2916a3e49934d482cd9b30b520c7873db4de82 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 7 Dec 2019 14:16:25 -0600 Subject: [PATCH] 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 --- lib/tokenlist.cpp | 2 +- test/testtokenize.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index eb42119e9..91d11aeae 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -883,7 +883,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state) compileUnaryOp(tok, state, compileExpression); else compileBinOp(tok, state, compileExpression); - if (Token::simpleMatch(tok, "}")) + while (Token::simpleMatch(tok, "}")) tok = tok->next(); } else break; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 610545bc3..a54ae343c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -474,6 +474,7 @@ private: TEST_CASE(checkLambdas); TEST_CASE(checkIfCppCast); TEST_CASE(checkRefQualifiers); + TEST_CASE(checkConditionBlock); // #9052 TEST_CASE(noCrash1); @@ -7692,6 +7693,7 @@ private: ASSERT_EQUALS("Abc({newreturn", testAst("return new A {b(c)};")); ASSERT_EQUALS("a{{return", testAst("return{{a}};")); ASSERT_EQUALS("a{b{,{return", testAst("return{{a},{b}};")); + ASSERT_EQUALS("stdvector::", testAst("std::vector>{{},{}}")); } void astbrackets() { // [] @@ -8178,6 +8180,12 @@ private: } + void checkConditionBlock() { + ASSERT_NO_THROW(tokenizeAndStringify("void a() {\n" + " for (auto b : std::vector>{{}, {}}) {}\n" + "}\n")) + } + void noCrash1() { ASSERT_NO_THROW(tokenizeAndStringify( "struct A {\n"