reference_expr_from_initializing.carbon 1.1 KB

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