value_expr_from_reference_deref.carbon 852 B

1234567891011121314151617181920212223242526272829303132
  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: 0: Heap{}, 1: C{}, 2: ptr<Allocation(1)>
  7. // CHECK:STDOUT: Initialize c from reference expression from deferenced pointer
  8. // CHECK:STDOUT: 0: Heap{}, 1: C{}, 2: ptr<Allocation(1)>
  9. // CHECK:STDOUT: c destroyed
  10. // CHECK:STDOUT: result: 0
  11. package ExplorerTest api;
  12. class C {
  13. destructor[self: Self] {
  14. Print("c destroyed");
  15. }
  16. }
  17. fn FromReferenceExpressionDeref() {
  18. var c_var: C = {};
  19. var c_ref: C* = &c_var;
  20. heap.PrintAllocs();
  21. Print("Initialize c from reference expression from deferenced pointer");
  22. let c: C = *c_ref;
  23. heap.PrintAllocs();
  24. }
  25. fn Main() -> i32 {
  26. FromReferenceExpressionDeref();
  27. return 0;
  28. }