Skip to content

Commit 5b5e43e

Browse files
Fix danmar#7459 False positive (inconclusive): function can be static (danmar#6719)
1 parent 04f7a9b commit 5b5e43e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/checkclass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,8 @@ void CheckClass::checkConst()
21112111
// don't warn for friend/static/virtual functions
21122112
if (func.isFriend() || func.isStatic() || func.hasVirtualSpecifier())
21132113
continue;
2114+
if (func.functionPointerUsage)
2115+
continue;
21142116

21152117
// don't suggest const when returning non-const pointer/reference, but still suggest static
21162118
auto isPointerOrReference = [this](const Token* start, const Token* end) -> bool {

test/testclass.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class TestClass : public TestFixture {
185185
TEST_CASE(const91);
186186
TEST_CASE(const92);
187187
TEST_CASE(const93);
188+
TEST_CASE(const94);
188189

189190
TEST_CASE(const_handleDefaultParameters);
190191
TEST_CASE(const_passThisToMemberOfOtherClass);
@@ -6691,6 +6692,19 @@ class TestClass : public TestFixture {
66916692
errout_str());
66926693
}
66936694

6695+
void const94() { // #7459
6696+
checkConst("class A {\n"
6697+
"public:\n"
6698+
" A() : tickFunction(&A::nop) {}\n"
6699+
" void tick() { (this->*tickFunction)(); }\n"
6700+
"private:\n"
6701+
" typedef void (A::* Fn)();\n"
6702+
" Fn tickFunction;\n"
6703+
" void nop() {}\n"
6704+
"};\n");
6705+
ASSERT_EQUALS("", errout_str());
6706+
}
6707+
66946708
void const_handleDefaultParameters() {
66956709
checkConst("struct Foo {\n"
66966710
" void foo1(int i, int j = 0) {\n"

0 commit comments

Comments
 (0)