From 8c3e3faa07c01bbda0bf95e0b0af6e70de14458f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 24 Feb 2009 17:48:11 +0000 Subject: [PATCH] checkclass: refactoring --- src/checkclass.cpp | 6 +++--- test/testunusedprivfunc.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/checkclass.cpp b/src/checkclass.cpp index 7c5fdca7a..c51e54545 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -476,7 +476,7 @@ void CheckClass::privateFunctions() // The class implementation must be available.. const std::string classconstructor(classname + " :: " + classname); - if (!Token::findmatch(_tokenizer->tokens(), classconstructor.c_str())) + if (tok1->fileIndex()>0 && !Token::findmatch(_tokenizer->tokens(), classconstructor.c_str())) continue; // Get private functions.. @@ -549,13 +549,13 @@ void CheckClass::privateFunctions() { if (ftok->str() == "{") ++indent_level; - if (ftok->str() == "}") + else if (ftok->str() == "}") { if (indent_level <= 1) break; --indent_level; } - if (Token::Match(ftok->next(), "(")) + else if (Token::Match(ftok, "%var% (")) { // Remove function from FuncList for (std::list::iterator it = FuncList.begin(); it != FuncList.end(); ++it) diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 10b489f4d..a96d3c955 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -36,6 +36,7 @@ private: void run() { TEST_CASE(test1); + TEST_CASE(test2); // [ 2236547 ] False positive --style unused function, called via pointer TEST_CASE(func_pointer); @@ -81,6 +82,26 @@ private: } + void test2() + { + check("class A {\n" + "public:\n" + " A();\n" + "\n" + " void a() const\n" + " { b(); }\n" + "private:\n" + " void b( ) const\n" + " { }\n" + "};\n" + "\n" + "A::A()\n" + "{ }\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } + + +