value_expr_binding_from_initializing_expr.carbon 933 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. // CHECK:STDOUT: Bind from c initializing expression
  7. // CHECK:STDOUT: 0: Heap{}, 1: !Uninit<class C>
  8. // CHECK:STDOUT: 0: Heap{}, 1: C{}
  9. // CHECK:STDOUT: Binding scope end
  10. // CHECK:STDOUT: c destroyed
  11. // CHECK:STDOUT: 0: Heap{}, 1: !!C{}
  12. // CHECK:STDOUT: result: 0
  13. package ExplorerTest api;
  14. class C {
  15. fn Create() -> C {
  16. heap.PrintAllocs();
  17. return Create2();
  18. }
  19. fn Create2() -> C {
  20. return {};
  21. }
  22. destructor[self: Self] {
  23. Print("c destroyed");
  24. }
  25. }
  26. fn CallWithValueExpressionBinding(c: C) {
  27. heap.PrintAllocs();
  28. Print("Binding scope end");
  29. }
  30. fn Main() -> i32 {
  31. Print("Bind from c initializing expression");
  32. CallWithValueExpressionBinding(C.Create());
  33. heap.PrintAllocs();
  34. return 0;
  35. }