Interop support for initialization via std::initializer_list. (#6672)

Add a new builtin function `cpp.std.initializer_list.make` that takes an
array and returns a `std::initializer_list`, initialized to refer to
that array. When C++ initialization wants to perform a
`std::initializer_list`-from-array construction, synthesize a
declaration of a matching builtin function and use that to perform the
initialization.

Ideally we would specify this conversion as an impl of `ImplicitAs` in
the prelude instead of hardcoding it in the interop layer, but
unfortunately that's not currently possible, for various reasons -- we
can't make the conversion form-generic, we can't deduce the array length
from the initializer, and we can't deduce against the arguments of
imported C++ class templates yet -- so for now synthesizing a builtin
function on demand is the best we can do.

Assisted-by: Gemini 3 Pro via Antigravity
This commit is contained in:
Richard Smith
2026-01-30 22:24:18 +00:00
committed by GitHub
parent 20a5c43e95
commit c0b24047dd
27 changed files with 2137 additions and 525 deletions
+2 -1
View File
@@ -1784,7 +1784,8 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context,
case SemIR::BuiltinFunctionKind::IntRightShiftAssign:
case SemIR::BuiltinFunctionKind::PointerMakeNull:
case SemIR::BuiltinFunctionKind::PointerIsNull:
case SemIR::BuiltinFunctionKind::PointerUnsafeConvert: {
case SemIR::BuiltinFunctionKind::PointerUnsafeConvert:
case SemIR::BuiltinFunctionKind::CppStdInitializerListMake: {
// These are runtime-only builtins.
// TODO: Consider tracking this on the `BuiltinFunctionKind`.
return SemIR::ConstantId::NotConstant;