reference_expr_from_value.carbon 743 B

123456789101112131415161718192021222324252627282930313233
  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 FromValueExpression() {
  13. let c_let: C = {};
  14. heap.PrintAllocs();
  15. Print("Initialize c from value expression");
  16. var c: C = c_let;
  17. heap.PrintAllocs();
  18. }
  19. fn Main() -> i32 {
  20. FromValueExpression();
  21. return 0;
  22. }
  23. // CHECK:STDOUT: 0: Heap{}, 1: C{}
  24. // CHECK:STDOUT: Initialize c from value expression
  25. // CHECK:STDOUT: 0: Heap{}, 1: C{}, 2: C{}
  26. // CHECK:STDOUT: c destroyed
  27. // CHECK:STDOUT: c destroyed
  28. // CHECK:STDOUT: result: 0