mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:51:11 +01:00
Support list initialization of C++ classes that is performed via a constructor call. (#6660)
The general strategy here is to import the constructor with a signature that directly matches the argument. The intent is that the imported function will eventually be usable directly as the `ImplicitAs.Convert` function in a generated `impl`. For initialization from a tuple, for example `(1, 2)`, we import the selected constructor with a signature that takes a tuple pattern: `fn Class.Class((a: i32, b: i32)) -> Class;` In order to support that, this PR also adds support in general for tuple patterns in function signatures. It turns out the implementation was already very close to allowing this. Assisted-by: Gemini 3 Pro via Antigravity
This commit is contained in:
@@ -53,7 +53,7 @@ namespace {
|
||||
// See `GetDeclForCoreInterface`.
|
||||
struct DeclInfo {
|
||||
clang::NamedDecl* decl;
|
||||
int num_params;
|
||||
SemIR::ClangDeclKey::Signature signature;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -68,9 +68,10 @@ auto GetDeclForCoreInterface(clang::Sema& clang_sema,
|
||||
case CoreInterface::Copy:
|
||||
return {.decl = clang_sema.LookupCopyingConstructor(
|
||||
class_decl, clang::Qualifiers::Const),
|
||||
.num_params = 1};
|
||||
.signature = {.num_params = 1}};
|
||||
case CoreInterface::Destroy:
|
||||
return {.decl = clang_sema.LookupDestructor(class_decl), .num_params = 0};
|
||||
return {.decl = clang_sema.LookupDestructor(class_decl),
|
||||
.signature = {.num_params = 0}};
|
||||
case CoreInterface::Unknown:
|
||||
CARBON_FATAL("shouldn't be called with `Unknown`");
|
||||
}
|
||||
@@ -102,7 +103,7 @@ auto LookupCppImpl(Context& context, SemIR::LocId loc_id,
|
||||
}
|
||||
|
||||
auto fn_id =
|
||||
ImportCppFunctionDecl(context, loc_id, cpp_fn, decl_info.num_params);
|
||||
ImportCppFunctionDecl(context, loc_id, cpp_fn, decl_info.signature);
|
||||
if (fn_id == SemIR::ErrorInst::InstId) {
|
||||
return SemIR::ErrorInst::InstId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user