Skip to content
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
7 changes: 7 additions & 0 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,13 @@ void CheckClass::checkConst()
const bool suggestStatic = memberAccessed != MemberAccess::MEMBER && !func.isOperator();
if ((returnsPtrOrRef || func.isConst() || func.hasLvalRefQualifier()) && !suggestStatic)
continue;
if (suggestStatic && func.isConst()) {
const auto overloads = func.getOverloadedFunctions();
if (overloads.size() > 1 && std::any_of(overloads.begin(), overloads.end(), [&](const Function* ovl) {
return &func != ovl && func.argCount() == ovl->argCount() && func.argsMatch(ovl->functionScope, ovl->argDef, func.argDef, emptyString, 0);
}))
continue;
}

std::string classname = scope->className;
const Scope *nest = scope->nestedIn;
Expand Down
10 changes: 10 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class TestClass : public TestFixture {
TEST_CASE(const97);
TEST_CASE(const98);
TEST_CASE(const99);
TEST_CASE(const100);

TEST_CASE(const_handleDefaultParameters);
TEST_CASE(const_passThisToMemberOfOtherClass);
Expand Down Expand Up @@ -6855,6 +6856,15 @@ class TestClass : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void const100() {
checkConst("struct S {\n" // #14023
" void f() { ++i; }\n"
" void f() const {}\n"
" int i;\n"
"};\n");
ASSERT_EQUALS("", errout_str());
}

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