Bailout in private function usage checking for operators (#5059).

This commit is contained in:
PKEuS 2014-03-23 10:06:14 +01:00
parent 8d5be8c4a4
commit 77c17100ec
2 changed files with 14 additions and 1 deletions

View File

@ -873,7 +873,7 @@ void CheckClass::privateFunctions()
std::list<const Function*> FuncList; std::list<const Function*> FuncList;
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
// Get private functions.. // Get private functions..
if (func->type == Function::eFunction && func->access == Private) if (func->type == Function::eFunction && func->access == Private && !func->isOperator) // TODO: There are smarter ways to check private operator usage
FuncList.push_back(&*func); FuncList.push_back(&*func);
} }

View File

@ -579,6 +579,19 @@ private:
" }\n" " }\n"
"};"); "};");
ASSERT_EQUALS("[test.cpp:8]: (style) Unused private function: 'Fred::startListening'\n", errout.str()); ASSERT_EQUALS("[test.cpp:8]: (style) Unused private function: 'Fred::startListening'\n", errout.str());
// #5059
check("class Fred {\n"
" void* operator new(size_t obj_size, size_t buf_size) {}\n"
"};");
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Unused private function: 'Fred::operatornew'\n", "", errout.str()); // No message for operators - we currently cannot check their usage
check("class Fred {\n"
" void* operator new(size_t obj_size, size_t buf_size) {}\n"
"public:\n"
" void* foo() { return new(size) Fred(); }\n"
"};");
ASSERT_EQUALS("", errout.str());
} }
void testDoesNotIdentifyMethodAsFirstFunctionArgument() { void testDoesNotIdentifyMethodAsFirstFunctionArgument() {