reference_expr_from_initializing.carbon 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 CallWithReturnExpression() -> C {
  13. Print("Entering call");
  14. heap.PrintAllocs();
  15. var c: C = {};
  16. Print("Object created, returning");
  17. heap.PrintAllocs();
  18. return c;
  19. }
  20. fn FromInitializingExpression_ReturnExpr() {
  21. Print("Initialize c from initializing expression (return <expr>)");
  22. var c: C = CallWithReturnExpression();
  23. heap.PrintAllocs();
  24. }
  25. fn Main() -> i32 {
  26. FromInitializingExpression_ReturnExpr();
  27. return 0;
  28. }
  29. // CHECK:STDOUT: Initialize c from initializing expression (return <expr>)
  30. // CHECK:STDOUT: Entering call
  31. // CHECK:STDOUT: 0: Heap{}, 1: !Uninit<class C>
  32. // CHECK:STDOUT: Object created, returning
  33. // CHECK:STDOUT: 0: Heap{}, 1: !Uninit<class C>, 2: C{}
  34. // CHECK:STDOUT: c destroyed
  35. // CHECK:STDOUT: 0: Heap{}, 1: C{}, 2: !!C{}
  36. // CHECK:STDOUT: c destroyed
  37. // CHECK:STDOUT: result: 0