diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 00a8fdd72..d923ca7b3 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1487,16 +1487,10 @@ static Token * createAstAtToken(Token *tok, bool cpp) return tok->linkAt(1); if (Token::Match(tok, "%type% %name%|*|&|::") && tok->str() != "return") { - bool decl = false; Token *typetok = tok; - while (Token::Match(typetok, "%type%|::|*|&")) { - if (typetok->isStandardType() || Token::Match(typetok, "struct|const|static")) - decl = true; + while (Token::Match(typetok, "%type%|::|*|&")) typetok = typetok->next(); - } - if (!typetok) - return nullptr; - if (decl && Token::Match(typetok->previous(), "[*&] %var% =")) + if (Token::Match(typetok, "%var% =") && typetok->varId()) tok = typetok; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index e2e2c8197..d31179610 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7781,6 +7781,8 @@ private: "Ref r;\n" "int x(0);"; ASSERT_EQUALS("unoRef:: x0(", testAst(code1)); + + ASSERT_EQUALS("vary=", testAst("std::string var = y;")); } void astunaryop() { // unary operators