From 9551332321489d2c6fa24b99e4dadcee4e46f8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 22 Jan 2011 13:00:03 +0100 Subject: [PATCH] Fixed #2459 (False positive with unused private function and friend) --- lib/checkclass.cpp | 5 +++++ test/testunusedprivfunc.cpp | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index c59fcb35e..f8a7ddda4 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -583,6 +583,11 @@ void CheckClass::privateFunctions() if (Token::findmatch(_tokenizer->tokens(), "; __property ;")) return; + // skip checking if there are friends + // Todo: check if each class has friends + if (Token::findmatch(_tokenizer->tokens(), "friend")) + return; + // #2407 calls from operator() is not detected // TODO: Don't bailout. Detect the call. if (Token::findmatch(_tokenizer->tokens(), "operator ( )")) diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index d5e6c3c8c..ff6f84c60 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -53,6 +53,8 @@ private: TEST_CASE(derivedClass); // skip warning for derived classes. It might be a virtual function. + TEST_CASE(friendClass); + TEST_CASE(borland); // skip FP when using __property // No false positives when there are "unused" templates that are removed in the simplified token list @@ -387,6 +389,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void friendClass() + { + // ticket #2459 - friend class + check("class Foo {\n" + "private:\n" + " friend Bar;\n" + " void f() { }\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + void borland() { // ticket #2034 - Borland C++ __property