Fixed #1932 (false positive: unused private function)
This commit is contained in:
parent
c8087d3389
commit
54b7f972c9
|
@ -1173,7 +1173,12 @@ void CheckClass::privateFunctions()
|
||||||
{
|
{
|
||||||
// Final check; check if the function pointer is used somewhere..
|
// Final check; check if the function pointer is used somewhere..
|
||||||
const std::string _pattern("return|(|)|,|= " + FuncList.front()->str());
|
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());
|
unusedPrivateFunctionError(FuncList.front(), classname, FuncList.front()->str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ private:
|
||||||
// [ 2236547 ] False positive --style unused function, called via pointer
|
// [ 2236547 ] False positive --style unused function, called via pointer
|
||||||
TEST_CASE(func_pointer1);
|
TEST_CASE(func_pointer1);
|
||||||
TEST_CASE(func_pointer2);
|
TEST_CASE(func_pointer2);
|
||||||
|
TEST_CASE(func_pointer3);
|
||||||
|
|
||||||
TEST_CASE(ctor);
|
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()
|
void ctor()
|
||||||
|
|
Loading…
Reference in New Issue