value_expr_binding_from_initializing_expr.carbon 934 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. package ExplorerTest api;
  7. class C {
  8. fn Create() -> C {
  9. heap.PrintAllocs();
  10. return Create2();
  11. }
  12. fn Create2() -> C {
  13. return {};
  14. }
  15. destructor[self: Self] {
  16. Print("c destroyed");
  17. }
  18. }
  19. fn CallWithValueExpressionBinding(c: C) {
  20. heap.PrintAllocs();
  21. Print("Binding scope end");
  22. }
  23. fn Main() -> i32 {
  24. Print("Bind from c initializing expression");
  25. CallWithValueExpressionBinding(C.Create());
  26. heap.PrintAllocs();
  27. return 0;
  28. }
  29. // CHECK:STDOUT: Bind from c initializing expression
  30. // CHECK:STDOUT: 0: Heap{}, 1: !Uninit<class C>
  31. // CHECK:STDOUT: 0: Heap{}, 1: C{}
  32. // CHECK:STDOUT: Binding scope end
  33. // CHECK:STDOUT: c destroyed
  34. // CHECK:STDOUT: 0: Heap{}, 1: !!C{}
  35. // CHECK:STDOUT: result: 0