Skip to content

Commit 8f29685

Browse files
committed
Fix #14023 FP functionStatic (inconclusive) for const overload
1 parent f28aeae commit 8f29685

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/checkclass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,13 @@ void CheckClass::checkConst()
21732173
const bool suggestStatic = memberAccessed != MemberAccess::MEMBER && !func.isOperator();
21742174
if ((returnsPtrOrRef || func.isConst() || func.hasLvalRefQualifier()) && !suggestStatic)
21752175
continue;
2176+
if (suggestStatic && func.isConst()) {
2177+
const auto overloads = func.getOverloadedFunctions();
2178+
if (overloads.size() > 1 && std::any_of(overloads.begin(), overloads.end(), [&](const Function* ovl) {
2179+
return &func != ovl && func.argCount() == ovl->argCount() && func.argsMatch(ovl->functionScope, ovl->argDef, func.argDef, emptyString, 0);
2180+
}))
2181+
continue;
2182+
}
21762183

21772184
std::string classname = scope->className;
21782185
const Scope *nest = scope->nestedIn;

test/testclass.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class TestClass : public TestFixture {
189189
TEST_CASE(const96);
190190
TEST_CASE(const97);
191191
TEST_CASE(const98);
192+
TEST_CASE(const99);
192193

193194
TEST_CASE(const_handleDefaultParameters);
194195
TEST_CASE(const_passThisToMemberOfOtherClass);
@@ -6835,6 +6836,16 @@ class TestClass : public TestFixture {
68356836
ASSERT_EQUALS("", errout_str());
68366837
}
68376838

6839+
6840+
void const99() {
6841+
checkConst("struct S {\n" // #14023
6842+
" void f() { ++i; }\n"
6843+
" void f() const {}\n"
6844+
" int i;\n"
6845+
"};\n");
6846+
ASSERT_EQUALS("", errout_str());
6847+
}
6848+
68386849
void const_handleDefaultParameters() {
68396850
checkConst("struct Foo {\n"
68406851
" void foo1(int i, int j = 0) {\n"

0 commit comments

Comments
 (0)