Skip to content

Commit 140480f

Browse files
Fix #14023 FP functionStatic (inconclusive) for const overload (danmar#7679)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 4b794ee commit 140480f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/checkclass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,13 @@ void CheckClass::checkConst()
21892189
const bool suggestStatic = memberAccessed != MemberAccess::MEMBER && !func.isOperator();
21902190
if ((returnsPtrOrRef || func.isConst() || func.hasLvalRefQualifier()) && !suggestStatic)
21912191
continue;
2192+
if (suggestStatic && func.isConst()) {
2193+
const auto overloads = func.getOverloadedFunctions();
2194+
if (overloads.size() > 1 && std::any_of(overloads.begin(), overloads.end(), [&](const Function* ovl) {
2195+
return &func != ovl && func.argCount() == ovl->argCount() && func.argsMatch(ovl->functionScope, ovl->argDef, func.argDef, emptyString, 0);
2196+
}))
2197+
continue;
2198+
}
21922199

21932200
std::string classname = scope->className;
21942201
const Scope *nest = scope->nestedIn;

test/testclass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class TestClass : public TestFixture {
190190
TEST_CASE(const97);
191191
TEST_CASE(const98);
192192
TEST_CASE(const99);
193+
TEST_CASE(const100);
193194

194195
TEST_CASE(const_handleDefaultParameters);
195196
TEST_CASE(const_passThisToMemberOfOtherClass);
@@ -6855,6 +6856,15 @@ class TestClass : public TestFixture {
68556856
ASSERT_EQUALS("", errout_str());
68566857
}
68576858

6859+
void const100() {
6860+
checkConst("struct S {\n" // #14023
6861+
" void f() { ++i; }\n"
6862+
" void f() const {}\n"
6863+
" int i;\n"
6864+
"};\n");
6865+
ASSERT_EQUALS("", errout_str());
6866+
}
6867+
68586868
void const_handleDefaultParameters() {
68596869
checkConst("struct Foo {\n"
68606870
" void foo1(int i, int j = 0) {\n"

0 commit comments

Comments
 (0)