Fixed #677 (False positive: Unused private function produced by class member initialization)

This commit is contained in:
Daniel Marjamäki 2009-09-16 23:04:13 +02:00
parent c5368581d9
commit 1dc738b1ae
2 changed files with 15 additions and 2 deletions

View File

@ -518,6 +518,7 @@ void CheckClass::privateFunctions()
break;
--indent_level;
}
else if (indent_level != 1)
continue;
else if (tok->str() == "private:")
@ -529,10 +530,10 @@ void CheckClass::privateFunctions()
else if (priv)
{
if (Token::Match(tok, "typedef %type% ("))
tok = tok->tokAt(2);
tok = tok->tokAt(2)->link();
else if (Token::Match(tok, "[:,] %var% ("))
tok = tok->tokAt(2);
tok = tok->tokAt(2)->link();
else if (Token::Match(tok, "%var% (") &&
!Token::Match(tok, classname.c_str()))

View File

@ -38,6 +38,7 @@ private:
TEST_CASE(test2);
TEST_CASE(test3);
TEST_CASE(test4);
TEST_CASE(test5);
// [ 2236547 ] False positive --style unused function, called via pointer
TEST_CASE(func_pointer);
@ -56,6 +57,7 @@ private:
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
@ -191,6 +193,16 @@ private:
}
void test5()
{
check("class A {\n"
"private:\n"
" A() : lock(new Lock())\n"
" { }\n"
" Lock *lock;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}