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)