reset.pass.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // shared_ptr
  10. // void reset();
  11. #include <memory>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. struct B
  15. {
  16. static int count;
  17. B() {++count;}
  18. B(const B&) {++count;}
  19. virtual ~B() {--count;}
  20. };
  21. int B::count = 0;
  22. struct A
  23. : public B
  24. {
  25. static int count;
  26. A() {++count;}
  27. A(const A&) {++count;}
  28. ~A() {--count;}
  29. };
  30. int A::count = 0;
  31. int main(int, char**)
  32. {
  33. {
  34. std::shared_ptr<B> p(new B);
  35. p.reset();
  36. assert(A::count == 0);
  37. assert(B::count == 0);
  38. assert(p.use_count() == 0);
  39. assert(p.get() == 0);
  40. }
  41. assert(A::count == 0);
  42. {
  43. std::shared_ptr<B> p;
  44. p.reset();
  45. assert(A::count == 0);
  46. assert(B::count == 0);
  47. assert(p.use_count() == 0);
  48. assert(p.get() == 0);
  49. }
  50. assert(A::count == 0);
  51. return 0;
  52. }