Skip to content

Commit 29bbb4c

Browse files
committed
Fixed #9220 (False positive: Unused function check for template parameter)
1 parent 23d37e5 commit 29bbb4c

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

lib/checkunusedfunctions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
197197
funcname = tok;
198198
} else if ((lambdaEndToken || tok->scope()->isExecutable()) && Token::Match(tok, "%name% <") && Token::simpleMatch(tok->linkAt(1), "> (")) {
199199
funcname = tok;
200+
} else if (Token::Match(tok, "< %name%") && tok->link()) {
201+
funcname = tok->next();
202+
while (Token::Match(funcname, "%name% :: %name%"))
203+
funcname = funcname->tokAt(2);
200204
} else if (Token::Match(tok, "[;{}.,()[=+-/|!?:]")) {
201205
funcname = tok->next();
202206
if (funcname && funcname->str() == "&")

test/testunusedfunctions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class TestUnusedFunctions : public TestFixture {
4545
TEST_CASE(template2);
4646
TEST_CASE(template3);
4747
TEST_CASE(template4); // #9805
48+
TEST_CASE(template5);
4849
TEST_CASE(throwIsNotAFunction);
4950
TEST_CASE(unusedError);
5051
TEST_CASE(unusedMain);
@@ -248,6 +249,18 @@ class TestUnusedFunctions : public TestFixture {
248249
ASSERT_EQUALS("", errout.str());
249250
}
250251

252+
void template5() { // #9220
253+
check("void f(){}\n"
254+
"\n"
255+
"typedef void(*Filter)();\n"
256+
"\n"
257+
"template <Filter fun>\n"
258+
"void g() { fun(); }\n"
259+
"\n"
260+
"int main() { g<f>(); return 0;}");
261+
ASSERT_EQUALS("", errout.str());
262+
}
263+
251264
void throwIsNotAFunction() {
252265
check("struct A {void f() const throw () {}}; int main() {A a; a.f();}");
253266
ASSERT_EQUALS("", errout.str());

0 commit comments

Comments
 (0)