From 80fdf1ca51a0a0bd5e871af3b90d3c4b29ab99bd Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 2 Sep 2010 19:22:54 +0200 Subject: [PATCH] Symbol database: Fixed false negatives for unused private functions. Ticket: #1895 --- lib/checkclass.cpp | 30 +++++++++++++++++++++--------- test/testunusedprivfunc.cpp | 4 ++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 200fc33cd..0083a4783 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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::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::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); } } diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 5f7ad8024..8d0fd075a 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -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"