Skip to content

Commit 21d4c79

Browse files
Fix #12904 FN unusedFunction with function named like unknown type (#8417)
1 parent 8ee2ccb commit 21d4c79

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/checkunusedfunctions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const Setting
261261
while (Token::Match(funcname, "%name% :: %name%"))
262262
funcname = funcname->tokAt(2);
263263

264+
if (funcname && funcname->isName() && !funcname->function() && !tok->astParent() && Token::Match(tok, "[(,]")) // unknown type in parameter list
265+
continue;
266+
264267
if (!Token::Match(funcname, "%name% [(),;]:}<>]"))
265268
continue;
266269
}

test/testunusedfunctions.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class TestUnusedFunctions : public TestFixture {
8686
TEST_CASE(attributeUnused);
8787
TEST_CASE(attributeMaybeUnused);
8888
TEST_CASE(staticFunction);
89+
TEST_CASE(unnamedArg);
8990
}
9091

9192
struct CheckOptions
@@ -827,6 +828,16 @@ class TestUnusedFunctions : public TestFixture {
827828
"}\n", dinit(CheckOptions, $.cpp = false));
828829
ASSERT_EQUALS("[test.c:1:6]: (style) The function 'f' should have static linkage since it is not used outside of its translation unit. [staticFunction]\n", errout_str());
829830
}
831+
832+
void unnamedArg()
833+
{
834+
check("struct S {\n" // #12904
835+
" void Type() {}\n"
836+
"};\n"
837+
"[[unused]] void f(Type) {}\n"
838+
"[[unused]] void g(Type, Type) {}\n");
839+
ASSERT_EQUALS("[test.cpp:2:10]: (style) The function 'Type' is never used. [unusedFunction]\n", errout_str());
840+
}
830841
};
831842

832843
REGISTER_TEST(TestUnusedFunctions)

0 commit comments

Comments
 (0)