Fixed #9533 (Syntax Error: AST broken, 'for' doesn't have two operands incrementing pointer in initializer)
This commit is contained in:
parent
0c659a1499
commit
d31d778bf4
|
@ -1372,6 +1372,11 @@ static Token * createAstAtToken(Token *tok, bool cpp)
|
|||
Token *tok2 = skipDecl(tok->tokAt(2));
|
||||
Token *init1 = nullptr;
|
||||
Token * const endPar = tok->next()->link();
|
||||
if (tok2 == tok->tokAt(2) && Token::Match(tok2, "%op%|(")) {
|
||||
init1 = tok2;
|
||||
AST_state state1(cpp);
|
||||
compileExpression(tok2, state1);
|
||||
} else {
|
||||
while (tok2 && tok2 != endPar && tok2->str() != ";") {
|
||||
if (tok2->str() == "<" && tok2->link()) {
|
||||
tok2 = tok2->link();
|
||||
|
@ -1387,6 +1392,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
|
|||
return nullptr;
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
}
|
||||
if (!tok2 || tok2->str() != ";") {
|
||||
if (tok2 == endPar && init1) {
|
||||
tok->next()->astOperand2(init1);
|
||||
|
|
|
@ -7524,6 +7524,7 @@ private:
|
|||
ASSERT_EQUALS("forx*0=yz;;(", testAst("for(*x=0;y;z)"));
|
||||
ASSERT_EQUALS("forx0=y(8<z;;(", testAst("for (x=0;(int)y<8;z);"));
|
||||
ASSERT_EQUALS("forab,c:(", testAst("for (auto [a,b]: c);"));
|
||||
ASSERT_EQUALS("fora*++;;(", testAst("for (++(*a);;);"));
|
||||
|
||||
// problems with multiple expressions
|
||||
ASSERT_EQUALS("ax( whilex(", testAst("a(x) while (x)"));
|
||||
|
|
Loading…
Reference in New Issue