From 29bbb4ce14bb431f9c8c8a7d3812d7fc1f3c183f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 12 Sep 2021 20:27:49 +0200 Subject: [PATCH] Fixed #9220 (False positive: Unused function check for template parameter) --- lib/checkunusedfunctions.cpp | 4 ++++ test/testunusedfunctions.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 39f10f829..5b6700783 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -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() == "&") diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index ac36f1fa8..6fab7fd09 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -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 \n" + "void g() { fun(); }\n" + "\n" + "int main() { g(); 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());