Skip to content

Commit

Permalink
Fix #12867 (Wrong ast: 'i{0}' in for loop init expression) (#6709)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar authored Aug 17, 2024
1 parent 9aa63a7 commit 7e1cec8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ static Token* skipDecl(Token* tok, std::vector<Token*>* inner = nullptr)
vartok = vartok->link();
else
return tok;
} else if (Token::Match(vartok, "%var% [:=(]")) {
} else if (Token::Match(vartok, "%var% [:=({]")) {
return vartok;
} else if (Token::Match(vartok, "decltype|typeof (") && !isDecltypeFuncParam(tok->linkAt(1))) {
if (inner)
Expand Down Expand Up @@ -1622,7 +1622,7 @@ static Token * createAstAtToken(Token *tok)
while (tok2 && tok2 != endPar && tok2->str() != ";") {
if (tok2->str() == "<" && tok2->link()) {
tok2 = tok2->link();
} else if (Token::Match(tok2, "%name% )| %op%|(|[|.|:|::") || Token::Match(tok2->previous(), "[(;{}] %cop%|(")) {
} else if (Token::Match(tok2, "%name% )| %op%|(|[|{|.|:|::") || Token::Match(tok2->previous(), "[(;{}] %cop%|(")) {
init1 = tok2;
AST_state state1(cpp);
compileExpression(tok2, state1);
Expand Down
1 change: 1 addition & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6134,6 +6134,7 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("fori0=iasize.(<i++;;( asize.(", testAst("for (decltype(a.size()) i = 0; i < a.size(); ++i);"));
ASSERT_EQUALS("foria:( asize.(", testAst("for(decltype(a.size()) i:a);"));
ASSERT_EQUALS("forec0{([,(:( fb.return", testAst("for (auto e : c(0, [](auto f) { return f->b; }));")); // #10802
ASSERT_EQUALS("forvar1{;;(", testAst("for(int var{1};;)")); // #12867

// for with initializer (c++20)
ASSERT_EQUALS("forab=ca:;(", testAst("for(a=b;int c:a)"));
Expand Down

0 comments on commit 7e1cec8

Please sign in to comment.