Skip to content

Commit 54b7f97

Browse files
eriklaxDaniel Marjamäki
authored andcommitted
Fixed danmar#1932 (false positive: unused private function)
1 parent c8087d3 commit 54b7f97

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/checkclass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,12 @@ void CheckClass::privateFunctions()
11731173
{
11741174
// Final check; check if the function pointer is used somewhere..
11751175
const std::string _pattern("return|(|)|,|= " + FuncList.front()->str());
1176-
if (!Token::findmatch(_tokenizer->tokens(), _pattern.c_str()))
1176+
1177+
// or if the function address is used somewhere...
1178+
// eg. sigc::mem_fun(this, &className::classFunction)
1179+
const std::string _pattern2("& " + classname + " :: " + FuncList.front()->str());
1180+
if (!Token::findmatch(_tokenizer->tokens(), _pattern.c_str()) &&
1181+
!Token::findmatch(_tokenizer->tokens(), _pattern2.c_str()))
11771182
{
11781183
unusedPrivateFunctionError(FuncList.front(), classname, FuncList.front()->str());
11791184
}

test/testunusedprivfunc.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class TestUnusedPrivateFunction : public TestFixture
4343
// [ 2236547 ] False positive --style unused function, called via pointer
4444
TEST_CASE(func_pointer1);
4545
TEST_CASE(func_pointer2);
46+
TEST_CASE(func_pointer3);
4647

4748
TEST_CASE(ctor);
4849

@@ -254,6 +255,19 @@ class TestUnusedPrivateFunction : public TestFixture
254255
}
255256

256257

258+
void func_pointer3()
259+
{
260+
check("class c1\n"
261+
"{\n"
262+
"public:\n"
263+
" c1()\n"
264+
" { sigc::mem_fun(this, &c1::f1); }\n"
265+
"\n"
266+
"private:\n"
267+
" void f1() const {}\n"
268+
"};\n");
269+
ASSERT_EQUALS("", errout.str());
270+
}
257271

258272

259273
void ctor()

0 commit comments

Comments
 (0)