reference_expr_binding_from_reference.carbon 830 B

1234567891011121314151617181920212223242526272829303132333435
  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. destructor[self: Self] {
  9. Print("c destroyed");
  10. }
  11. }
  12. fn CallWithReferenceExpressionBinding(var c: C) {
  13. Print("Binding scope end");
  14. }
  15. fn Main() -> i32 {
  16. var c_var: C = {};
  17. heap.PrintAllocs();
  18. Print("Bind from c reference expression");
  19. CallWithReferenceExpressionBinding(c_var);
  20. heap.PrintAllocs();
  21. return 0;
  22. }
  23. // CHECK:STDOUT: 0: Heap{}, 1: C{}
  24. // CHECK:STDOUT: Bind from c reference expression
  25. // CHECK:STDOUT: Binding scope end
  26. // CHECK:STDOUT: c destroyed
  27. // CHECK:STDOUT: 0: Heap{}, 1: C{}, 2: !!C{}
  28. // CHECK:STDOUT: c destroyed
  29. // CHECK:STDOUT: result: 0