value_expr_from_initializing.carbon 997 B

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