mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +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:
@@ -174,11 +174,11 @@ auto HandleParseNode(Context& context, Parse::ForHeaderId node_id) -> bool {
|
||||
auto cursor_var_id = cursor_var_block.AddInstWithCleanup<SemIR::VarStorage>(
|
||||
node_id,
|
||||
{.type_id = cursor_type_id, .pattern_id = SemIR::AbsoluteInstId::None});
|
||||
// Disable broken lint that suggests a "fix" that doesn't compile.
|
||||
auto init_result = Initialize(context, node_id,
|
||||
// NOLINTNEXTLINE(performance-move-const-arg)
|
||||
std::move(cursor_var_id),
|
||||
std::move(cursor_var_block), cursor_id);
|
||||
auto init_result = Initialize(
|
||||
context, node_id,
|
||||
// Disable broken lint that suggests a "fix" that doesn't compile.
|
||||
// NOLINTNEXTLINE(performance-move-const-arg)
|
||||
std::move(cursor_var_id), std::move(cursor_var_block), cursor_id);
|
||||
AddInst<SemIR::Assign>(
|
||||
context, node_id,
|
||||
{.lhs_id = init_result.storage_id, .rhs_id = init_result.init_id});
|
||||
|
||||
Reference in New Issue
Block a user