Fixed false positive "unused function" #5113.

This commit is contained in:
PKEuS 2014-03-26 12:34:21 +01:00
parent 3e6423f92b
commit 6c4e8761c8
2 changed files with 17 additions and 2 deletions

View File

@ -178,13 +178,13 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
funcname = funcname->next();
}
else if (Token::Match(tok, "[=(,] &| %var% :: %var%")) {
else if (Token::Match(tok, "[;{}.,()[=+-/|!?:] &| %var% :: %var%")) {
funcname = tok->next();
if (funcname->str() == "&")
funcname = funcname->next();
while (Token::Match(funcname,"%var% :: %var%"))
funcname = funcname->tokAt(2);
if (!Token::Match(funcname, "%var% [,);]"))
if (!Token::Match(funcname, "%var% [(),;:}]"))
continue;
}

View File

@ -50,6 +50,7 @@ private:
TEST_CASE(returnRef);
TEST_CASE(attribute); // #3471 - FP __attribute__(constructor)
TEST_CASE(initializer_list);
TEST_CASE(member_function_ternary);
TEST_CASE(multipleFiles); // same function name in multiple files
@ -295,6 +296,20 @@ private:
ASSERT_EQUALS("", errout.str());
}
void member_function_ternary() {
check("struct Foo {\n"
" void F1() {}\n"
" void F2() {}\n"
"};\n"
"int main(int argc, char *argv[]) {\n"
" Foo foo;\n"
" void (Foo::*ptr)();\n"
" ptr = (argc > 1 && !strcmp(argv[1], \"F2\")) ? &Foo::F2 : &Foo::F1;\n"
" (foo.*ptr)();\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void multipleFiles() {
CheckUnusedFunctions c;