Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12898, #12899 FN unusedFunction #6574

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/checkunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const Setting
while (Token::Match(funcname, "%name% :: %name%"))
funcname = funcname->tokAt(2);

if (!Token::Match(funcname, "%name% [(),;]:}>]") || funcname->varId())
if (!Token::Match(funcname, "%name% [(),;]:}>]"))
continue;
}

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

// funcname ( => Assert that the end parentheses isn't followed by {
Expand Down
7 changes: 0 additions & 7 deletions lib/valueptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ class CPPCHECKLIB ValuePtr {
}
ValuePtr(ValuePtr&& rhs) NOEXCEPT : mPtr(std::move(rhs.mPtr)), mClone(std::move(rhs.mClone)) {}

/**
* Releases the shared_ptr's ownership of the managed object using the .reset() function
*/
void release() {
mPtr.reset();
}

T* get() NOEXCEPT {
return mPtr.get();
}
Expand Down
21 changes: 21 additions & 0 deletions test/testunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class TestUnusedFunctions : public TestFixture {

TEST_CASE(includes);
TEST_CASE(virtualFunc);
TEST_CASE(parensInit);
}

#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
Expand Down Expand Up @@ -542,6 +543,15 @@ class TestUnusedFunctions : public TestFixture {
ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Break' is never used.\n"
"[test.cpp:5]: (style) The function 'Break1' is never used.\n",
errout_str());

check("struct S {\n" // #12899
" void f() {}\n"
"};\n"
"enum E { f };\n"
"int main() {\n"
" E e{ f };\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'f' is never used.\n", errout_str());
}

void recursive() {
Expand Down Expand Up @@ -735,6 +745,17 @@ class TestUnusedFunctions : public TestFixture {
"}\n");
ASSERT_EQUALS("", errout_str());
}

void parensInit()
{
check("struct S {\n" // #12898
" void url() {}\n"
"};\n"
"int main() {\n"
" const int url(0);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'url' is never used.\n", errout_str());
}
};

REGISTER_TEST(TestUnusedFunctions)
Loading