new_and_delete.carbon 683 B

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