From 9d1d7ebf8d745400e24d2c9f132d7f5c0371ebe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 7 Jul 2009 08:30:23 +0200 Subject: [PATCH] Fixed #382 (False positive: public function flagged as 'Unused private function') --- src/checkclass.cpp | 4 +++- test/testunusedprivfunc.cpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/checkclass.cpp b/src/checkclass.cpp index b208f1675..788afc0c2 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -463,13 +463,15 @@ void CheckClass::privateFunctions() break; --indent_level; } + else if (indent_level != 1) + continue; else if (tok->str() == "private:") priv = true; else if (tok->str() == "public:") priv = false; else if (tok->str() == "protected:") priv = false; - else if (priv && indent_level == 1) + else if (priv) { if (Token::Match(tok, "typedef %type% (")) tok = tok->tokAt(2); diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 93eea2bc7..56ed7f4f3 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -43,6 +43,8 @@ private: TEST_CASE(func_pointer); TEST_CASE(ctor); + + TEST_CASE(classInClass); } @@ -235,6 +237,23 @@ private: } + void classInClass() + { + check("class A\n" + "{\n" + "public:\n" + "\n" + " class B\n" + " {\n" + " private:\n" + " };\n" + "\n" + " static void f()\n" + " { }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + }; REGISTER_TEST(TestUnusedPrivateFunction)