Skip to content

Commit

Permalink
Fix #7459 False positive (inconclusive): function can be static (#6719)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Aug 26, 2024
1 parent 04f7a9b commit 5b5e43e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 5b5e43e

Please sign in to comment.