new_and_delete.carbon 686 B

1234567891011121314151617181920212223242526272829303132333435
  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. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. class A{
  8. fn Create() -> A {
  9. return {};
  10. }
  11. destructor[self: Self] {
  12. Print("DESTRUCTOR A");
  13. }
  14. }
  15. fn Main() -> i32 {
  16. Print("Allocate A");
  17. var pa: A* = heap.New(A.Create());
  18. Print("Delete A");
  19. heap.Delete(pa);
  20. Print("Return");
  21. return 0;
  22. }
  23. // CHECK:STDOUT: Allocate A
  24. // CHECK:STDOUT: DESTRUCTOR A
  25. // CHECK:STDOUT: Delete A
  26. // CHECK:STDOUT: DESTRUCTOR A
  27. // CHECK:STDOUT: Return
  28. // CHECK:STDOUT: result: 0