diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 8448ff815..794b2d482 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1553,8 +1553,22 @@ static Token * createAstAtToken(Token *tok, bool cpp) typecount++; typetok = typetok->next(); } - if (Token::Match(typetok, "%var% =") && typetok->varId()) - tok = typetok; + if (Token::Match(typetok, "%var% =|[") && typetok->varId()) { + Token *tok2 = typetok->next(); + while (Token::simpleMatch(tok2, "[")) + tok2 = tok2->link()->next(); + if (Token::simpleMatch(tok2, "=")) { + AST_state state(cpp); + state.op.push(typetok); + Token * const start = tok2; + compileBinOp(tok2, state, compileAssignTernary); + if (tok2 == start || !tok2) + return start; + createAstAtTokenInner(start->next(), tok2, cpp); + return tok2; + } else if (Token::simpleMatch(tok2, ";")) + return tok; + } // Do not create AST for function declaration if (typetok && diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 50632a02e..a28d0a9b2 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7857,7 +7857,7 @@ private: void astvardecl() { // Variable declaration - ASSERT_EQUALS("a1[\"\"=", testAst("char a[1]=\"\";")); + ASSERT_EQUALS("var\"\"=", testAst("char var[1]=\"\";")); ASSERT_EQUALS("charp*(3[char5[3[new=", testAst("char (*p)[3] = new char[5][3];")); ASSERT_EQUALS("varp=", testAst("const int *var = p;"));