diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 180b8e9c3..26dee1a18 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -734,8 +734,11 @@ void CheckClass::privateFunctions() // or if the function address is used somewhere... // eg. sigc::mem_fun(this, &className::classFunction) const std::string _pattern2("& " + classname + " :: " + FuncList.front()->str()); + const std::string methodAsArgument("(|, " + classname + " :: " + FuncList.front()->str() + " ,|)"); if (!Token::findmatch(_tokenizer->tokens(), _pattern.c_str()) && - !Token::findmatch(_tokenizer->tokens(), _pattern2.c_str())) + !Token::findmatch(_tokenizer->tokens(), _pattern2.c_str()) && + !Token::findmatch(_tokenizer->tokens(), methodAsArgument.c_str()) + ) { unusedPrivateFunctionError(FuncList.front(), classname, FuncList.front()->str()); } diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 2257644e7..d5e6c3c8c 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -60,7 +60,9 @@ private: // #2407 - FP when called from operator() TEST_CASE(fp_operator); - TEST_CASE(testDoesNotIdentifyCallback); // #2480 + TEST_CASE(testDoesNotIdentifyMethodAsFirstFunctionArgument); // #2480 + TEST_CASE(testDoesNotIdentifyMethodAsMiddleFunctionArgument); + TEST_CASE(testDoesNotIdentifyMethodAsLastFunctionArgument); } @@ -449,7 +451,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testDoesNotIdentifyCallback() + void testDoesNotIdentifyMethodAsFirstFunctionArgument() { check("#include " "void callback(void (*func)(int), int arg)" @@ -474,8 +476,66 @@ private: "{" " MountOperation aExample(10);" "}" - ); - TODO_ASSERT_EQUALS("", errout.str()); + ); + ASSERT_EQUALS("", errout.str()); + } + + void testDoesNotIdentifyMethodAsMiddleFunctionArgument() + { + check("#include " + "void callback(char, void (*func)(int), int arg)" + "{" + " (*func)(arg);" + "}" + "class MountOperation" + "{" + " static void Completed(int i);" + "public:" + " MountOperation(int i);" + "};" + "void MountOperation::Completed(int i)" + "{" + " std::cerr << i << std::endl;" + "}" + "MountOperation::MountOperation(int i)" + "{" + " callback('a', MountOperation::Completed, i);" + "}" + "int main(void)" + "{" + " MountOperation aExample(10);" + "}" + ); + ASSERT_EQUALS("", errout.str()); + } + + void testDoesNotIdentifyMethodAsLastFunctionArgument() + { + check("#include " + "void callback(int arg, void (*func)(int))" + "{" + " (*func)(arg);" + "}" + "class MountOperation" + "{" + " static void Completed(int i);" + "public:" + " MountOperation(int i);" + "};" + "void MountOperation::Completed(int i)" + "{" + " std::cerr << i << std::endl;" + "}" + "MountOperation::MountOperation(int i)" + "{" + " callback(i, MountOperation::Completed);" + "}" + "int main(void)" + "{" + " MountOperation aExample(10);" + "}" + ); + ASSERT_EQUALS("", errout.str()); } };