From a97e28491fd634686f5c59e10f4fa32bd4cd45bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 16 Jan 2011 12:16:31 +0100 Subject: [PATCH] Fixed #2407 (False positive: unused private function) --- lib/checkclass.cpp | 5 +++++ test/testunusedprivfunc.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index ffcc55633..9b211cc34 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -199,6 +199,11 @@ void CheckClass::privateFunctions() if (Token::findmatch(_tokenizer->tokens(), "; __property ;")) return; + // #2407 calls from operator() is not detected + // TODO: Don't bailout. Detect the call. + if (Token::findmatch(_tokenizer->tokens(), "operator ( )")) + return; + createSymbolDatabase(); std::list::iterator i; diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 6260bd0bd..d3474daa0 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -57,6 +57,9 @@ private: // No false positives when there are "unused" templates that are removed in the simplified token list TEST_CASE(template1); + + // #2407 - FP when called from operator() + TEST_CASE(fp_operator); } @@ -414,6 +417,36 @@ private: "};\n"); ASSERT_EQUALS("", errout.str()); } + + void fp_operator() + { + // #2407 - FP when function is called from operator() + check("class Fred\n" + "{\n" + "public:\n" + " void operator()(int x) {\n" + " startListening();\n" + " }\n" + "\n" + "private:\n" + " void startListening() {\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + + check("class Fred\n" + "{\n" + "public:\n" + " void operator()(int x) {\n" + " }\n" + "\n" + "private:\n" + " void startListening() {\n" + " }\n" + "};\n"); + TODO_ASSERT_EQUALS("[test.cpp:8]: (style) Unused private function 'Fred::startListening'\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestUnusedPrivateFunction)