Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4404,10 +4404,12 @@ void Tokenizer::setVarIdClassFunction(const std::string &classname,
std::map<nonneg int, std::map<std::string, nonneg int>>& structMembers,
nonneg int &varId_)
{
const auto pos = classname.rfind(' '); // TODO handle multiple scopes
const std::string lastScope = classname.substr(pos == std::string::npos ? 0 : pos + 1);
for (Token *tok2 = startToken; tok2 && tok2 != endToken; tok2 = tok2->next()) {
if (tok2->varId() != 0 || !tok2->isName())
continue;
if (Token::Match(tok2->tokAt(-2), ("!!" + classname + " ::").c_str()))
if (Token::Match(tok2->tokAt(-2), ("!!" + lastScope + " ::").c_str()))
continue;
if (Token::Match(tok2->tokAt(-4), "%name% :: %name% ::")) // Currently unsupported
continue;
Expand Down
24 changes: 24 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class TestVarID : public TestFixture {
TEST_CASE(varid_namespace_3); // #8627
TEST_CASE(varid_namespace_4);
TEST_CASE(varid_namespace_5);
TEST_CASE(varid_namespace_6);
TEST_CASE(varid_initList);
TEST_CASE(varid_initListWithBaseTemplate);
TEST_CASE(varid_initListWithScope);
Expand Down Expand Up @@ -2200,6 +2201,29 @@ class TestVarID : public TestFixture {
"9: }\n", tokenize(code, "test.cpp"));
}

void varid_namespace_6() {
const char code[] = "namespace N {\n" // #12077
" namespace O {\n"
" U::U(int* map) : id(0) {\n"
" this->p = map;\n"
" }\n"
" void U::f() {\n"
" std::map<Vec2i, int>::iterator iter;\n"
" }\n"
" }\n"
"}";
ASSERT_EQUALS("1: namespace N {\n"
"2: namespace O {\n"
"3: U :: U ( int * map@1 ) : id ( 0 ) {\n"
"4: this . p = map@1 ;\n"
"5: }\n"
"6: void U :: f ( ) {\n"
"7: std :: map < Vec2i , int > :: iterator iter@2 ;\n"
"8: }\n"
"9: }\n"
"10: }\n", tokenize(code, "test.cpp"));
}

void varid_initList() {
const char code1[] = "class A {\n"
" A() : x(0) {}\n"
Expand Down