From 3c3a56bfca2f5383161b016815e86e006635e532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 14 Apr 2009 21:46:13 +0200 Subject: [PATCH] private functions: don't report false positives when using initialization lists (#254) --- src/checkclass.cpp | 7 +++++-- test/testunusedprivfunc.cpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/checkclass.cpp b/src/checkclass.cpp index 7883c03da..4978ea8e2 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -436,8 +436,11 @@ void CheckClass::privateFunctions() if (Token::Match(tok, "typedef %type% (")) tok = tok->tokAt(2); - if (Token::Match(tok, "%var% (") && - !Token::Match(tok, classname.c_str())) + else if (Token::Match(tok, "[:,] %var% (")) + tok = tok->tokAt(2); + + else if (Token::Match(tok, "%var% (") && + !Token::Match(tok, classname.c_str())) { FuncList.push_back(tok); } diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 549999da5..4241ac192 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -42,6 +42,8 @@ private: // [ 2236547 ] False positive --style unused function, called via pointer TEST_CASE(func_pointer); + + TEST_CASE(ctor); } @@ -166,6 +168,22 @@ private: } + void ctor() + { + check("class PrivateCtor\n" + "{\n" + "private:\n" + " PrivateCtor(int threadNum) :\n" + " numOfThreads(threadNum)\n" + " {\n" + " }\n" + "\n" + " int numOfThreads;\n" + "};\n"); + + ASSERT_EQUALS(std::string(""), errout.str()); + } + };