value_expr_from_reference_deref.carbon 857 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 FromReferenceExpressionDeref() {
  13. var c_var: C = {};
  14. var c_ref: C* = &c_var;
  15. heap.PrintAllocs();
  16. Print("Initialize c from reference expression from dereferenced pointer");
  17. let c: C = *c_ref;
  18. heap.PrintAllocs();
  19. }
  20. fn Main() -> i32 {
  21. FromReferenceExpressionDeref();
  22. return 0;
  23. }
  24. // CHECK:STDOUT: 0: Heap{}, 1: C{}, 2: ptr<Allocation(1)>
  25. // CHECK:STDOUT: Initialize c from reference expression from dereferenced pointer
  26. // CHECK:STDOUT: 0: Heap{}, 1: C{}, 2: ptr<Allocation(1)>
  27. // CHECK:STDOUT: c destroyed
  28. // CHECK:STDOUT: result: 0