diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fbb75d97e..faa7387ad 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4389,7 +4389,7 @@ void Tokenizer::setVarIdPass2() std::map &thisClassVars = varsByClass[scopeName2 + classname]; while (Token::Match(tokStart, ":|::|,|%name%")) { - if (Token::Match(tokStart, "%name% <")) { + if (Token::Match(tokStart, "%name% <")) { // TODO: why skip templates? tokStart = tokStart->next()->findClosingBracket(); if (tokStart) tokStart = tokStart->next(); @@ -4397,6 +4397,11 @@ void Tokenizer::setVarIdPass2() } if (Token::Match(tokStart, "%name% ,|{")) { std::string baseClassName = tokStart->str(); + const Token* baseStart = tokStart; + while (Token::Match(baseStart->tokAt(-2), "%name% ::")) { // build base class name + baseClassName.insert(0, baseStart->strAt(-2) + " :: "); + baseStart = baseStart->tokAt(-2); + } std::string scopeName3(scopeName2); while (!scopeName3.empty()) { const std::string name = scopeName3 + baseClassName; diff --git a/test/testvarid.cpp b/test/testvarid.cpp index ca589b050..d9805ffbe 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -135,6 +135,7 @@ private: TEST_CASE(varid_in_class20); // #7267 TEST_CASE(varid_in_class21); // #7788 TEST_CASE(varid_in_class22); // #10872 + TEST_CASE(varid_in_class23); // #11293 TEST_CASE(varid_namespace_1); // #7272 TEST_CASE(varid_namespace_2); // #7000 TEST_CASE(varid_namespace_3); // #8627 @@ -1964,6 +1965,28 @@ private: ASSERT_EQUALS(expected, tokenize(code, "test.cpp")); } + void varid_in_class23() { // #11293 + const char code[] = "struct A {\n" + " struct S {\n" + " bool b;\n" + " };\n" + "};\n" + "struct B : A::S {\n" + " void f() { b = false; }\n" + "};\n"; + + const char expected[] = "1: struct A {\n" + "2: struct S {\n" + "3: bool b@1 ;\n" + "4: } ;\n" + "5: } ;\n" + "6: struct B : A :: S {\n" + "7: void f ( ) { b@1 = false ; }\n" + "8: } ;\n"; + + ASSERT_EQUALS(expected, tokenize(code, "test.cpp")); + } + void varid_namespace_1() { // #7272 const char code[] = "namespace Blah {\n" " struct foo { int x;};\n"