diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index fa23d414bca..5356e4917d0 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -475,7 +475,7 @@ static Token* skipDecl(Token* tok, std::vector* 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) @@ -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); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6ffec57c4c7..f27e458137a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6134,6 +6134,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("fori0=iasize.(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)"));