Fixed #2407 (False positive: unused private function)
This commit is contained in:
parent
f72fd6960e
commit
a97e28491f
|
@ -199,6 +199,11 @@ void CheckClass::privateFunctions()
|
||||||
if (Token::findmatch(_tokenizer->tokens(), "; __property ;"))
|
if (Token::findmatch(_tokenizer->tokens(), "; __property ;"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// #2407 calls from operator() is not detected
|
||||||
|
// TODO: Don't bailout. Detect the call.
|
||||||
|
if (Token::findmatch(_tokenizer->tokens(), "operator ( )"))
|
||||||
|
return;
|
||||||
|
|
||||||
createSymbolDatabase();
|
createSymbolDatabase();
|
||||||
|
|
||||||
std::list<SymbolDatabase::SpaceInfo *>::iterator i;
|
std::list<SymbolDatabase::SpaceInfo *>::iterator i;
|
||||||
|
|
|
@ -57,6 +57,9 @@ private:
|
||||||
|
|
||||||
// No false positives when there are "unused" templates that are removed in the simplified token list
|
// No false positives when there are "unused" templates that are removed in the simplified token list
|
||||||
TEST_CASE(template1);
|
TEST_CASE(template1);
|
||||||
|
|
||||||
|
// #2407 - FP when called from operator()
|
||||||
|
TEST_CASE(fp_operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -414,6 +417,36 @@ private:
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fp_operator()
|
||||||
|
{
|
||||||
|
// #2407 - FP when function is called from operator()
|
||||||
|
check("class Fred\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" void operator()(int x) {\n"
|
||||||
|
" startListening();\n"
|
||||||
|
" }\n"
|
||||||
|
"\n"
|
||||||
|
"private:\n"
|
||||||
|
" void startListening() {\n"
|
||||||
|
" }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("class Fred\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" void operator()(int x) {\n"
|
||||||
|
" }\n"
|
||||||
|
"\n"
|
||||||
|
"private:\n"
|
||||||
|
" void startListening() {\n"
|
||||||
|
" }\n"
|
||||||
|
"};\n");
|
||||||
|
TODO_ASSERT_EQUALS("[test.cpp:8]: (style) Unused private function 'Fred::startListening'\n", errout.str());
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestUnusedPrivateFunction)
|
REGISTER_TEST(TestUnusedPrivateFunction)
|
||||||
|
|
Loading…
Reference in New Issue