Fixed #1537 ('Unused private function' when using pointer to member function)
This commit is contained in:
parent
26c447279c
commit
1b81a9d435
|
@ -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<const Token *>::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;
|
||||
|
|
|
@ -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<UnusedPrivateFunctionMemberPointer, unsigned> mObserver;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ctor()
|
||||
{
|
||||
check("class PrivateCtor\n"
|
||||
|
|
Loading…
Reference in New Issue