diff --git a/src/tokenize.cpp b/src/tokenize.cpp index fc62f19a6..a4c30d6ee 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -926,7 +926,10 @@ void Tokenizer::setVarId() if (Token::Match(tok, "[,;{}(] %type%")) tok = tok->next(); - if (Token::Match(tok, "else|return|typedef|delete|class")) + if (Token::Match(tok, "class|struct %type% :|{|;")) + continue; + + if (Token::Match(tok, "else|return|typedef|delete")) continue; if (Token::Match(tok, "const|static|extern|public:|private:|protected:")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 3d33c20ff..490acb39a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -97,6 +97,7 @@ private: TEST_CASE(varid9); TEST_CASE(varid10); TEST_CASE(varid11); + TEST_CASE(varid12); TEST_CASE(varidStl); TEST_CASE(varid_delete); TEST_CASE(varid_functions); @@ -1217,6 +1218,30 @@ private: ASSERT_EQUALS(expected, actual); } + void varid12() + { + const std::string code("static void a()\n" + "{\n" + " class Foo *foo;\n" + "}\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: static void a ( )\n" + "2: {\n" + "3: class Foo * foo@1 ;\n" + "4: }\n"); + + ASSERT_EQUALS(expected, actual); + } + void varidStl() { const std::string code("list ints;\n"