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

View File

@ -109,7 +109,7 @@ private:
"unsigned int Fred::f()\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"
"class Fred\n"
@ -125,7 +125,7 @@ private:
"{\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
check("#file \"p.h\"\n"