Symbol database: Fixed false negatives for unused private functions. Ticket: #1895

This commit is contained in:
Robert Reif 2010-09-02 19:22:54 +02:00 committed by Daniel Marjamäki
parent 2049f70754
commit 80fdf1ca51
2 changed files with 23 additions and 11 deletions

View File

@ -1208,10 +1208,23 @@ void CheckClass::privateFunctions()
// Locate some class // Locate some class
const Token *tok1 = info->classDef; const Token *tok1 = info->classDef;
/** @todo check that the whole class implementation is seen */ // check that the whole class implementation is seen
// until the todo above is fixed we only check classes that are bool whole = true;
// declared in the source file std::list<Func>::const_iterator func;
if (tok1->fileIndex() != 0) for (func = info->functionList.begin(); func != info->functionList.end(); ++func)
{
if (!func->hasBody)
{
// empty private copy constructors and assignment operators are OK
if ((func->type == Func::CopyConstructor || func->type == Func::OperatorEqual) && func->access == Private)
continue;
whole = false;
break;
}
}
if (!whole)
continue; continue;
const std::string &classname = tok1->next()->str(); const std::string &classname = tok1->next()->str();
@ -1220,13 +1233,12 @@ void CheckClass::privateFunctions()
/** @todo embedded class have access to private functions */ /** @todo embedded class have access to private functions */
if (info->nestedList.empty()) if (info->nestedList.empty())
{ {
std::list<Func>::const_iterator it; for (func = info->functionList.begin(); func != info->functionList.end(); ++func)
for (it = info->functionList.begin(); it != info->functionList.end(); ++it)
{ {
// Get private functions.. // Get private functions..
if (it->type == Func::Function && if (func->type == Func::Function &&
it->access == Private && it->hasBody) func->access == Private && func->hasBody)
FuncList.push_back(it->tokenDef); FuncList.push_back(func->tokenDef);
} }
} }

View File

@ -109,7 +109,7 @@ private:
"unsigned int Fred::f()\n" "unsigned int Fred::f()\n"
"{ }\n"); "{ }\n");
TODO_ASSERT_EQUALS("[p.h:4]: (style) Unused private function 'Fred::f'\n", errout.str()); ASSERT_EQUALS("[p.h:4]: (style) Unused private function 'Fred::f'\n", errout.str());
check("#file \"p.h\"\n" check("#file \"p.h\"\n"
"class Fred\n" "class Fred\n"
@ -125,7 +125,7 @@ private:
"{\n" "{\n"
"}\n" "}\n"
"\n"); "\n");
TODO_ASSERT_EQUALS("[p.h:4]: (style) Unused private function 'Fred::f'\n", errout.str()); ASSERT_EQUALS("[p.h:4]: (style) Unused private function 'Fred::f'\n", errout.str());
// Don't warn about include files which implementation we don't see // Don't warn about include files which implementation we don't see
check("#file \"p.h\"\n" check("#file \"p.h\"\n"