Fixed #382 (False positive: public function flagged as 'Unused private function')

This commit is contained in:
Daniel Marjamäki 2009-07-07 08:30:23 +02:00
parent 1a97090526
commit 9d1d7ebf8d
2 changed files with 22 additions and 1 deletions

View File

@ -463,13 +463,15 @@ void CheckClass::privateFunctions()
break; break;
--indent_level; --indent_level;
} }
else if (indent_level != 1)
continue;
else if (tok->str() == "private:") else if (tok->str() == "private:")
priv = true; priv = true;
else if (tok->str() == "public:") else if (tok->str() == "public:")
priv = false; priv = false;
else if (tok->str() == "protected:") else if (tok->str() == "protected:")
priv = false; priv = false;
else if (priv && indent_level == 1) else if (priv)
{ {
if (Token::Match(tok, "typedef %type% (")) if (Token::Match(tok, "typedef %type% ("))
tok = tok->tokAt(2); tok = tok->tokAt(2);

View File

@ -43,6 +43,8 @@ private:
TEST_CASE(func_pointer); TEST_CASE(func_pointer);
TEST_CASE(ctor); 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) REGISTER_TEST(TestUnusedPrivateFunction)