Extend CppRangeForIterate to support ADL begin/end (#7230)

`CppRangeForIterate` needs to support finding `begin()`/`end()` as a
pair of methods and as a pair of ADL-findable functions. This change
adds the ADL component, which lets us also diagnose types that don't
implement the interface.

Unlike methods, we apparently have support for overloads when using ADL.
This commit is contained in:
Christopher Di Bella
2026-05-22 21:12:06 +00:00
committed by GitHub
parent e6b1679552
commit 64e890c246
5 changed files with 1466 additions and 153 deletions
+3 -4
View File
@@ -745,8 +745,8 @@ auto IsCppOperatorMethod(Context& context, SemIR::InstId inst_id) -> bool {
return function_decl && IsCppOperatorMethodDecl(function_decl);
}
auto IsCppConstructorOrNonMethodOperator(Context& context,
SemIR::InstId inst_id) -> bool {
auto IsCppConstructorOrNonMethod(Context& context, SemIR::InstId inst_id)
-> bool {
auto* function_decl = GetAsCppFunctionDecl(context, inst_id);
if (!function_decl) {
return false;
@@ -754,8 +754,7 @@ auto IsCppConstructorOrNonMethodOperator(Context& context,
if (isa<clang::CXXConstructorDecl>(function_decl)) {
return true;
}
return !isa<clang::CXXMethodDecl>(function_decl) &&
function_decl->isOverloadedOperator();
return !isa<clang::CXXMethodDecl>(function_decl);
}
} // namespace Carbon::Check