diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a4c006e9d..3ce48269f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3207,7 +3207,7 @@ void Tokenizer::setVarId() if (c == varname[0]) { const std::string &prev = tok2->strAt(-1); - if (tok2->str() == varname && prev != "struct" && prev != "union" && prev != "::" && prev != ".") + if (tok2->str() == varname && prev != "struct" && prev != "union" && prev != "::" && prev != "." && tok2->strAt(1) != "::") tok2->varId(_varId); } else if (c == '{') diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7aff76dde..02b03d515 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -155,6 +155,7 @@ private: TEST_CASE(varid24); TEST_CASE(varid25); TEST_CASE(varid26); // ticket #1967 (list of function pointers) + TEST_CASE(varid27); // Ticket #2280 (same name for namespace and variable) TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); TEST_CASE(varidStl); @@ -2501,6 +2502,16 @@ private: ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } + void varid27() + { + const std::string code("int fooled_ya;\n" + "fooled_ya::iterator iter;\n"); + const std::string expected("\n\n##file 0\n" + "1: int fooled_ya@1 ;\n" + "2: fooled_ya :: iterator iter@2 ;\n"); + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); + } + void varidFunctionCall1() { const std::string code("void f() {\n"