Files
carbon-lang/explorer/testdata/let/value_expr_binding_from_value.carbon
T
Adrien LeravatandJon Ross-Perkins 9edfa9cad3 Explorer: Avoid unecessary copies when a value binding is created from a value expression (#3000)
#### Functional changes

* Avoid unnecessary copies when a value binding is created from a value
expression in call parameters
* Ensure the result of the value expression bound is destroyed
* Provide storage to initializing expressions used in call parameters

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2023-07-24 14:39:13 +00:00

34 lines
772 B
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDOUT: 0: Heap{}, 1: C{}
// CHECK:STDOUT: Bind from c value expression
// CHECK:STDOUT: Binding scope end
// CHECK:STDOUT: 0: Heap{}, 1: C{}
// CHECK:STDOUT: c destroyed
// CHECK:STDOUT: result: 0
package ExplorerTest api;
class C {
destructor[self: Self] {
Print("c destroyed");
}
}
fn CallWithValueExpressionBinding(c: C) {
Print("Binding scope end");
}
fn Main() -> i32 {
let c_let: C = {};
heap.PrintAllocs();
Print("Bind from c value expression");
CallWithValueExpressionBinding(c_let);
heap.PrintAllocs();
return 0;
}