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