From 9b5986505ef5336a07c3f53f0608de338cdf0f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 22 Jun 2020 08:34:08 +0200 Subject: [PATCH] AST; Improved ast for variable declaration with assignment --- lib/tokenlist.cpp | 10 ++-------- test/testtokenize.cpp | 2 ++ 2 files changed, 4 insertions(+), 8 deletions(-) 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