Support ranges with overloaded const/non-const begin and end. (#7627)

If we find an overload set containing mulitple methods, discard any
non-const methods and try again. This allows libc++'s `std::vector` to
be iterated with range-based for.
This commit is contained in:
Richard Smith
2026-08-11 19:14:37 +00:00
committed by GitHub
parent e10827ed84
commit 0f93cbd370
3 changed files with 521 additions and 0 deletions
+18
View File
@@ -397,6 +397,24 @@ static auto LookupCppMethod(Context& context, clang::Sema& clang_sema,
constexpr auto LookupKind = clang::Sema::LookupMemberName;
auto lookup_info = clang::LookupResult(clang_sema, name_info, LookupKind);
clang_sema.LookupQualifiedName(lookup_info, class_decl);
// If we found multiple results, drop anything that's not a const-qualified
// method and try again.
if (!lookup_info.isSingleResult()) {
auto filter = lookup_info.makeFilter();
while (filter.hasNext()) {
auto* decl = filter.next();
if (auto* method = dyn_cast<clang::CXXMethodDecl>(decl)) {
if (!method->getMethodQualifiers().hasConst()) {
filter.erase();
}
} else {
filter.erase();
}
}
filter.done();
}
if (lookup_info.empty()) {
return SemIR::InstId::None;
}