Skip to content

Commit

Permalink
Fix #12901 FN unusedFunction with cast (#6575)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 5, 2024
1 parent 1275c77 commit 747862f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const Setting
continue;
}

if (!funcname || funcname->isKeyword() || funcname->isStandardType() || funcname->varId() || funcname->enumerator())
if (!funcname || funcname->isKeyword() || funcname->isStandardType() || funcname->varId() || funcname->enumerator() || funcname->type())
continue;

// funcname ( => Assert that the end parentheses isn't followed by {
Expand Down
13 changes: 13 additions & 0 deletions test/testunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class TestUnusedFunctions : public TestFixture {
TEST_CASE(includes);
TEST_CASE(virtualFunc);
TEST_CASE(parensInit);
TEST_CASE(typeInCast);
}

#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
Expand Down Expand Up @@ -756,6 +757,18 @@ class TestUnusedFunctions : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'url' is never used.\n", errout_str());
}

void typeInCast()
{
check("struct S {\n" // #12901
" void Type() {}\n"
"};\n"
"int main() {\n"
" struct Type {} t;\n"
" Type t2{ (Type)t };\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'Type' is never used.\n", errout_str());
}
};

REGISTER_TEST(TestUnusedFunctions)

0 comments on commit 747862f

Please sign in to comment.