diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1bd13af87..5b493dfc2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3631,7 +3631,7 @@ void Tokenizer::setVarId() const std::string &prev = tok2->previous()->str(); /** @todo better handling when classes in different scopes have the same name */ - if (!className.empty() && Token::simpleMatch(tok2->tokAt(-2), className.c_str()) && prev == "::") + if (!className.empty() && Token::Match(tok2->tokAt(-3), ("!!:: " + className + " ::").c_str())) tok2->varId(_varId); else if (tok2->str() == varname && prev != "struct" && prev != "union" && prev != "::" && prev != "." && tok2->strAt(1) != "::") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 3dfb24f33..3d66b3a99 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -197,6 +197,7 @@ private: TEST_CASE(varidclass10); // variable declaration below usage TEST_CASE(varidclass11); // variable declaration below usage TEST_CASE(varidclass12); + TEST_CASE(varidclass13); TEST_CASE(file1); TEST_CASE(file2); @@ -3498,6 +3499,22 @@ private: ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } + void varidclass13() + { + const std::string code("class Fred {\n" + " int a;\n" + " void f() { Foo::Fred::a = 0; }\n" + "};\n"); + + const std::string expected("\n\n##file 0\n" + "1: class Fred {\n" + "2: int a@1 ;\n" + "3: void f ( ) { Foo :: Fred :: a = 0 ; }\n" + "4: } ;\n"); + + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); + } + void file1() { const char code[] = "a1\n"