Fix #359 (Incorrect unused function)

This commit is contained in:
Daniel Marjamäki 2009-06-05 15:02:26 +02:00
parent 8470cdafc0
commit cfb4e91986
2 changed files with 15 additions and 4 deletions

View File

@ -99,17 +99,18 @@ void CheckFunctionUsage::parseTokens(const Tokenizer &tokenizer)
if (Token::Match(tok->next(), "%var% ("))
{
if (tok->str() == "*" || (tok->isName() && !Token::Match(tok, "else|return")))
continue;
funcname = tok->next();
}
if (Token::Match(tok, "[;{}.,()[=+-/&|!?:] %var% [(),;:}]"))
else if (Token::Match(tok, "[;{}.,()[=+-/&|!?:] %var% [(),;:}]"))
funcname = tok->next();
if (Token::Match(tok, "[(,] & %var% :: %var% [,)]"))
else if (Token::Match(tok, "[(,] & %var% :: %var% [,)]"))
funcname = tok->tokAt(4);
else
continue;
// funcname ( => Assert that the end paranthesis isn't followed by {
if (Token::Match(funcname, "%var% ("))
{

View File

@ -37,6 +37,7 @@ private:
{
TEST_CASE(incondition);
TEST_CASE(return1);
TEST_CASE(return2);
TEST_CASE(callback1);
TEST_CASE(else1);
TEST_CASE(functionpointer);
@ -79,6 +80,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void return2()
{
check("char * foo()\n"
"{\n"
" return *foo();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void callback1()
{
check("void f1()\n"