Fix for #341 (Functions passed as pointer not detected as used)

This commit is contained in:
Daniel Marjamäki 2009-05-31 08:01:16 +02:00
parent 2cbbc65691
commit 375dfeab06
2 changed files with 18 additions and 0 deletions

View File

@ -107,6 +107,9 @@ void CheckFunctionUsage::parseTokens(const Tokenizer &tokenizer)
if (Token::Match(tok, "[;{}.,()[=+-/&|!?:] %var% [(),;:}]"))
funcname = tok->next();
if (Token::Match(tok, "[(,] & %var% :: %var% [,)]"))
funcname = tok->tokAt(4);
// funcname ( => Assert that the end paranthesis isn't followed by {
if (Token::Match(funcname, "%var% ("))
{

View File

@ -39,6 +39,7 @@ private:
TEST_CASE(return1);
TEST_CASE(callback1);
TEST_CASE(else1);
TEST_CASE(functionpointer);
}
void check(const char code[])
@ -98,6 +99,20 @@ private:
std::string err(errout.str());
ASSERT_EQUALS(std::string(""), errout.str());
}
void functionpointer()
{
check("namespace abc {\n"
"void foo() { }\n"
"};\n"
"\n"
"int main()\n"
"{\n"
" f(&abc::foo);\n"
" return 0\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
};
REGISTER_TEST(TestFunctionUsage)