Unused private function: return pointer to private function
This commit is contained in:
parent
0c910c9775
commit
58f0f03449
|
@ -511,6 +511,8 @@ void CheckClass::CheckUnusedPrivateFunctions()
|
|||
const char *_pattern[] = {"=","",NULL};
|
||||
_pattern[1] = FuncList.front().c_str();
|
||||
fp |= (Tokenizer::findtoken(tokens, _pattern) != NULL);
|
||||
_pattern[0] = "return";
|
||||
fp |= (Tokenizer::findtoken(tokens, _pattern) != NULL);
|
||||
_pattern[0] = "(";
|
||||
fp |= (Tokenizer::findtoken(tokens, _pattern) != NULL);
|
||||
_pattern[0] = ")";
|
||||
|
|
|
@ -36,6 +36,9 @@ private:
|
|||
void run()
|
||||
{
|
||||
TEST_CASE( test1 );
|
||||
|
||||
// [ 2236547 ] False positive --style unused function, called via pointer
|
||||
TEST_CASE( func_pointer );
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,7 +72,7 @@ private:
|
|||
" Fred();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"unsigned int Fred::Fred()\n"
|
||||
"Fred::Fred()\n"
|
||||
"{ }\n"
|
||||
"\n"
|
||||
"unsigned int Fred::f()\n"
|
||||
|
@ -77,6 +80,41 @@ private:
|
|||
|
||||
ASSERT_EQUALS( std::string("Class 'Fred', unused private function: 'f'\n"), errout.str() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void func_pointer()
|
||||
{
|
||||
check( "class Fred\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" typedef void (*testfp)();\n"
|
||||
"\n"
|
||||
" testfp get()\n"
|
||||
" {\n"
|
||||
" return test;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" static void test()\n"
|
||||
" { }\n"
|
||||
"\n"
|
||||
"public:\n"
|
||||
" Fred();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"Fred::Fred()\n"
|
||||
"{}\n" );
|
||||
|
||||
std::string str( errout.str() );
|
||||
|
||||
ASSERT_EQUALS( std::string("Class 'Fred', unused private function: 'get'\n"), str );
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST( TestUnusedPrivateFunction )
|
||||
|
|
Loading…
Reference in New Issue