From f4d18a8d1eb1e31998e653aa99d5b052536813d9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 21 Oct 2023 12:12:56 +0200 Subject: [PATCH] #12077 FP constStatement with ctor in namespace (#5572) --- lib/tokenize.cpp | 4 +++- test/testvarid.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6f82c551d..7c44a856c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4405,10 +4405,12 @@ void Tokenizer::setVarIdClassFunction(const std::string &classname, std::map>& 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; diff --git a/test/testvarid.cpp b/test/testvarid.cpp index fd8050a4d..e289f87ef 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -145,6 +145,7 @@ private: 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); @@ -2200,6 +2201,29 @@ private: "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::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"