Fixed #1932 (false positive: unused private function)

This commit is contained in:
Erik Lax 2010-08-15 07:44:08 +02:00 committed by Daniel Marjamäki
parent c8087d3389
commit 54b7f972c9
2 changed files with 20 additions and 1 deletions

View File

@ -1173,7 +1173,12 @@ void CheckClass::privateFunctions()
{
// Final check; check if the function pointer is used somewhere..
const std::string _pattern("return|(|)|,|= " + FuncList.front()->str());
if (!Token::findmatch(_tokenizer->tokens(), _pattern.c_str()))
// or if the function address is used somewhere...
// eg. sigc::mem_fun(this, &className::classFunction)
const std::string _pattern2("& " + classname + " :: " + FuncList.front()->str());
if (!Token::findmatch(_tokenizer->tokens(), _pattern.c_str()) &&
!Token::findmatch(_tokenizer->tokens(), _pattern2.c_str()))
{
unusedPrivateFunctionError(FuncList.front(), classname, FuncList.front()->str());
}

View File

@ -43,6 +43,7 @@ private:
// [ 2236547 ] False positive --style unused function, called via pointer
TEST_CASE(func_pointer1);
TEST_CASE(func_pointer2);
TEST_CASE(func_pointer3);
TEST_CASE(ctor);
@ -254,6 +255,19 @@ private:
}
void func_pointer3()
{
check("class c1\n"
"{\n"
"public:\n"
" c1()\n"
" { sigc::mem_fun(this, &c1::f1); }\n"
"\n"
"private:\n"
" void f1() const {}\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void ctor()