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 #7459 False positive (inconclusive): function can be static #6719

Merged
merged 1 commit into from
Aug 26, 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
2 changes: 2 additions & 0 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,8 @@ void CheckClass::checkConst()
// don't warn for friend/static/virtual functions
if (func.isFriend() || func.isStatic() || func.hasVirtualSpecifier())
continue;
if (func.functionPointerUsage)
continue;

// don't suggest const when returning non-const pointer/reference, but still suggest static
auto isPointerOrReference = [this](const Token* start, const Token* end) -> bool {
Expand Down
14 changes: 14 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class TestClass : public TestFixture {
TEST_CASE(const91);
TEST_CASE(const92);
TEST_CASE(const93);
TEST_CASE(const94);

TEST_CASE(const_handleDefaultParameters);
TEST_CASE(const_passThisToMemberOfOtherClass);
Expand Down Expand Up @@ -6691,6 +6692,19 @@ class TestClass : public TestFixture {
errout_str());
}

void const94() { // #7459
checkConst("class A {\n"
"public:\n"
" A() : tickFunction(&A::nop) {}\n"
" void tick() { (this->*tickFunction)(); }\n"
"private:\n"
" typedef void (A::* Fn)();\n"
" Fn tickFunction;\n"
" void nop() {}\n"
"};\n");
ASSERT_EQUALS("", errout_str());
}

void const_handleDefaultParameters() {
checkConst("struct Foo {\n"
" void foo1(int i, int j = 0) {\n"
Expand Down
Loading