diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 68eed2e7a..45ddb8183 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2908,7 +2908,7 @@ void Tokenizer::setVarId() unsigned int _varId = 0; for (Token *tok = _tokens; tok; tok = tok->next()) { - if (tok != _tokens && !Token::Match(tok, "[,;{}(] %type%")) + if (tok != _tokens && !Token::Match(tok, "[;{}(,] %type%")) continue; if (_errorLogger) @@ -2927,7 +2927,15 @@ void Tokenizer::setVarId() } if (Token::Match(tok, "[,;{}(] %type%")) + { + // not function declaration? + // TODO: Better checking + if (Token::Match(tok->tokAt(-2), "= %var% (")) + { + continue; + } tok = tok->next(); + } if (tok->str() == "new") continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5e9cc3d95..52e72786f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -150,6 +150,7 @@ private: TEST_CASE(varid24); TEST_CASE(varid25); TEST_CASE(varid26); // ticket #1967 (list of function pointers) + TEST_CASE(varid27); TEST_CASE(varidStl); TEST_CASE(varid_delete); TEST_CASE(varid_functions); @@ -2393,6 +2394,20 @@ private: ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } + void varid27() + { + const std::string code("void f() {\n" + " int x;\n" + " x = a(y*x,10);\n" + "}"); + const std::string expected("\n\n##file 0\n" + "1: void f ( ) {\n" + "2: int x@1 ;\n" + "3: x@1 = a ( y * x@1 , 10 ) ;\n" + "4: }\n"); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); + } + void varidStl() {