Skip to content

Commit e1cc0e2

Browse files
Fix #14033 Crash in CheckClass::checkConst() (#7695)
1 parent 140480f commit e1cc0e2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/checkclass.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,11 @@ void CheckClass::checkConst()
21922192
if (suggestStatic && func.isConst()) {
21932193
const auto overloads = func.getOverloadedFunctions();
21942194
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);
2195+
if (&func == ovl)
2196+
return false;
2197+
if (!ovl->functionScope)
2198+
return true;
2199+
return func.argCount() == ovl->argCount() && func.argsMatch(ovl->functionScope, ovl->argDef, func.argDef, emptyString, 0);
21962200
}))
21972201
continue;
21982202
}

test/testclass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6863,6 +6863,12 @@ class TestClass : public TestFixture {
68636863
" int i;\n"
68646864
"};\n");
68656865
ASSERT_EQUALS("", errout_str());
6866+
6867+
checkConst("struct S {\n" // #14033
6868+
" void f();\n"
6869+
" void f() const {}\n"
6870+
"};\n");
6871+
ASSERT_EQUALS("", errout_str()); // don't crash
68666872
}
68676873

68686874
void const_handleDefaultParameters() {

0 commit comments

Comments
 (0)