diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 47f710abf..2edae2696 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6180,7 +6180,7 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const std::string & */ const std::string classPattern(std::string(isStruct ? "struct " : "class ") + classname + " :|{"); const std::string internalPattern(std::string("!!~ ") + funcname + " ("); - const std::string externalPattern(std::string(classname) + " :: " + funcname + " ("); + const std::string externalPattern(classname + " :: " + funcname + " ("); for (; tok; tok = tok->next()) { @@ -6234,7 +6234,8 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const std::string & else if (indentlevel == 0 && Token::Match(tok, externalPattern.c_str())) { - return tok; + if (!Token::simpleMatch(tok->previous(), "::")) + return tok; } } diff --git a/test/testclass.cpp b/test/testclass.cpp index cf0253f6f..6bbaee42f 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -69,6 +69,7 @@ private: TEST_CASE(uninitOperator); // No FP about uninitialized 'operator[]' TEST_CASE(uninitFunction1); // No FP when initialized in function TEST_CASE(uninitFunction2); // No FP when initialized in function + TEST_CASE(uninitSameClassName); // No FP when two classes have the same name TEST_CASE(noConstructor1); TEST_CASE(noConstructor2); @@ -1574,6 +1575,33 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitSameClassName() + { + checkUninitVar("class B\n" + "{\n" + "public:\n" + " B();\n" + " int j;\n" + "};\n" + "\n" + "class A\n" + "{\n" + " class B\n" + " {\n" + " public:\n" + " B();\n" + " int i;\n" + " };\n" + "};\n" + "\n" + "A::B::B()\n" + "{\n" + " i = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + + void checkNoConstructor(const char code[]) { // Tokenize..