diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 0424528b0..630b1d740 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -773,7 +773,7 @@ void Tokenizer::setVarId() bool dot = false; for (tok2 = tok->next(); tok2; tok2 = tok2->next()) { - if (!dot && tok2->str() == varname) + if (!dot && tok2->str() == varname && !Token::Match(tok2->previous(), "struct|union")) tok2->varId(_varId); else if (tok2->str() == "{") ++indentlevel; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 3771c37c0..ef262a985 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -107,6 +107,7 @@ private: TEST_CASE(varidReturn); TEST_CASE(varid8); TEST_CASE(varid9); + TEST_CASE(varid10); TEST_CASE(varidStl); TEST_CASE(varid_delete); TEST_CASE(varid_functions); @@ -1145,6 +1146,32 @@ private: ASSERT_EQUALS(expected, actual); } + void varid10() + { + const std::string code("void foo()\n" + "{\n" + " int abc;\n" + " struct abc abc1;\n" + "}"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.setVarId(); + + // result.. + const std::string actual(tokenizer.tokens()->stringifyList(true)); + const std::string expected("\n\n##file 0\n" + "1: void foo ( )\n" + "2: {\n" + "3: int abc@1 ;\n" + "4: struct abc abc1@2 ;\n" + "5: }\n"); + + ASSERT_EQUALS(expected, actual); + } + void varidStl() { const std::string code("list ints;\n"