diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 517b5b2ee..94bf50e6e 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -704,7 +704,7 @@ void CheckClass::privateFunctions() } // Check member class functions to see what functions are used.. - if ((inclass && indent_level == 1 && Token::Match(ftok, ") const| {")) || + if ((inclass && indent_level == 1 && Token::Match(ftok, "%var% (")) || (Token::Match(ftok, (classname + " :: ~| %var% (").c_str()))) { while (ftok && ftok->str() != ")") @@ -714,7 +714,21 @@ void CheckClass::privateFunctions() if (Token::Match(ftok, ") : %var% (")) { while (!Token::Match(ftok->next(), "[{};]")) + { + if (Token::Match(ftok, "::|,|( %var% ,|)")) + { + // Remove function from FuncList + std::list::iterator it = FuncList.begin(); + while (it != FuncList.end()) + { + if (ftok->next()->str() == (*it)->str()) + FuncList.erase(it++); + else + it++; + } + } ftok = ftok->next(); + } } if (!Token::Match(ftok, ") const| {")) continue; diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index dd97634fc..3c99140cd 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -41,7 +41,8 @@ private: TEST_CASE(test5); // [ 2236547 ] False positive --style unused function, called via pointer - TEST_CASE(func_pointer); + TEST_CASE(func_pointer1); + TEST_CASE(func_pointer2); TEST_CASE(ctor); @@ -208,7 +209,7 @@ private: - void func_pointer() + void func_pointer1() { check("class Fred\n" "{\n" @@ -234,6 +235,27 @@ private: } + + void func_pointer2() + { + check("class UnusedPrivateFunctionMemberPointer\n" + "{\n" + "public:\n" + " UnusedPrivateFunctionMemberPointer()\n" + " : mObserver(this, &UnusedPrivateFunctionMemberPointer::callback)\n" + " {}\n" + "\n" + "private:\n" + " void callback(const& unsigned) const {}\n" + "\n" + " Observer mObserver;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + + + + void ctor() { check("class PrivateCtor\n"