From 37c889ab301c2ed7d043577a7fda0e4d60eca59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 2 Mar 2009 20:40:24 +0000 Subject: [PATCH] unused private function: better handling of initialization lists in constructors --- src/checkclass.cpp | 5 +++++ test/testunusedprivfunc.cpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/checkclass.cpp b/src/checkclass.cpp index 2371686c4..6d02469f8 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -551,6 +551,11 @@ void CheckClass::privateFunctions() ftok = ftok->next(); if (!ftok) break; + if (Token::Match(ftok, ") : %var% (")) + { + while (!Token::Match(ftok->next(), "[{};]")) + ftok = ftok->next(); + } if (!Token::Match(ftok, ") const| {")) continue; diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 16e36afee..f64e72a0d 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -38,6 +38,7 @@ private: TEST_CASE(test1); TEST_CASE(test2); TEST_CASE(test3); + TEST_CASE(test4); // [ 2236547 ] False positive --style unused function, called via pointer TEST_CASE(func_pointer); @@ -118,6 +119,22 @@ private: } + void test4() + { + check("class A {\n" + "public:\n" + " A();\n" + "private:\n" + " bool _owner;\n" + " void b() { }\n" + "};\n" + "\n" + "A::A() : _owner(false)\n" + "{ b(); }\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } + +