reset.pass.cpp 891 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <memory>
  9. // weak_ptr
  10. // void swap(weak_ptr& r);
  11. #include <memory>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. struct A
  15. {
  16. static int count;
  17. A() {++count;}
  18. A(const A&) {++count;}
  19. ~A() {--count;}
  20. };
  21. int A::count = 0;
  22. int main(int, char**)
  23. {
  24. {
  25. std::shared_ptr<A> p1(new A);
  26. std::weak_ptr<A> w1(p1);
  27. assert(w1.use_count() == 1);
  28. w1.reset();
  29. assert(w1.use_count() == 0);
  30. assert(p1.use_count() == 1);
  31. }
  32. assert(A::count == 0);
  33. return 0;
  34. }