Fixed #9220 (False positive: Unused function check for template parameter)

This commit is contained in:
Daniel Marjamäki 2021-09-12 20:27:49 +02:00
parent 23d37e5e7b
commit 29bbb4ce14
2 changed files with 17 additions and 0 deletions

View File

@ -197,6 +197,10 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
funcname = tok;
} else if ((lambdaEndToken || tok->scope()->isExecutable()) && Token::Match(tok, "%name% <") && Token::simpleMatch(tok->linkAt(1), "> (")) {
funcname = tok;
} else if (Token::Match(tok, "< %name%") && tok->link()) {
funcname = tok->next();
while (Token::Match(funcname, "%name% :: %name%"))
funcname = funcname->tokAt(2);
} else if (Token::Match(tok, "[;{}.,()[=+-/|!?:]")) {
funcname = tok->next();
if (funcname && funcname->str() == "&")

View File

@ -45,6 +45,7 @@ private:
TEST_CASE(template2);
TEST_CASE(template3);
TEST_CASE(template4); // #9805
TEST_CASE(template5);
TEST_CASE(throwIsNotAFunction);
TEST_CASE(unusedError);
TEST_CASE(unusedMain);
@ -248,6 +249,18 @@ private:
ASSERT_EQUALS("", errout.str());
}
void template5() { // #9220
check("void f(){}\n"
"\n"
"typedef void(*Filter)();\n"
"\n"
"template <Filter fun>\n"
"void g() { fun(); }\n"
"\n"
"int main() { g<f>(); return 0;}");
ASSERT_EQUALS("", errout.str());
}
void throwIsNotAFunction() {
check("struct A {void f() const throw () {}}; int main() {A a; a.f();}");
ASSERT_EQUALS("", errout.str());