mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Import non-const rvalue references as var parameters. (#7125)
When importing a C++ function with an rvalue reference parameter, we previously produced a Carbon value parameter. This would lead to the toolchain believing it could pass the address of a non-expiring object to the function, which would lead to a use-after-move. Instead, we now map non-const rvalue reference parameters to Carbon `var` parameters. This forces the object passed into C++ to be unique and owned by the call. While that's not an exact match for C++ rvalue reference parameters, given that it provides "always move" not "conditionally move", it's the closest match we have at the moment.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "toolchain/check/cpp/type_mapping.h"
|
||||
#include "toolchain/check/function.h"
|
||||
#include "toolchain/check/inst.h"
|
||||
#include "toolchain/check/pattern.h"
|
||||
#include "toolchain/check/type.h"
|
||||
#include "toolchain/check/type_completion.h"
|
||||
#include "toolchain/sem_ir/builtin_function_kind.h"
|
||||
@@ -266,6 +267,7 @@ static auto MakeCppStdInitializerListMake(Context& context, SemIR::LocId loc_id,
|
||||
{.parent_scope_id = init_list_class.scope_id,
|
||||
.name_id = init_list_class.name_id,
|
||||
.param_type_ids = {array_type_id},
|
||||
.param_kind = ParamPatternKind::Value,
|
||||
.return_type_id = init_list_type_id});
|
||||
|
||||
auto& function = context.functions().Get(function_id);
|
||||
|
||||
Reference in New Issue
Block a user