mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:54:47 +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:
@@ -681,9 +681,9 @@ auto MatchContext::DoVarPreWorkImpl(State state, SemIR::TypeId pattern_type_id,
|
||||
auto storage_id = storage_block.AddInstWithCleanup<SemIR::VarStorage>(
|
||||
SemIR::LocId(entry.pattern_id),
|
||||
{.type_id = pattern_type_id, .pattern_id = entry.pattern_id});
|
||||
// Disable broken lint that suggests a "fix" that doesn't compile.
|
||||
auto init_result = Initialize(
|
||||
context_, SemIR::LocId(entry.pattern_id),
|
||||
// Disable broken lint that suggests a "fix" that doesn't compile.
|
||||
// NOLINTNEXTLINE(performance-move-const-arg)
|
||||
std::move(storage_id), std::move(storage_block), scrutinee_id);
|
||||
// TODO: Consider instead creating something like a `Temporary`
|
||||
|
||||
Reference in New Issue
Block a user