pointer_throw.pass.cpp 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: libcpp-no-exceptions
  10. // UNSUPPORTED: sanitizer-new-delete
  11. // <memory>
  12. // template<class Y> explicit shared_ptr(Y* p);
  13. #include <memory>
  14. #include <new>
  15. #include <cstdlib>
  16. #include <cassert>
  17. #include "count_new.hpp"
  18. struct A
  19. {
  20. static int count;
  21. A() {++count;}
  22. A(const A&) {++count;}
  23. ~A() {--count;}
  24. };
  25. int A::count = 0;
  26. int main()
  27. {
  28. A* ptr = new A;
  29. assert(A::count == 1);
  30. globalMemCounter.throw_after = 0;
  31. try
  32. {
  33. std::shared_ptr<A> p(ptr);
  34. assert(false);
  35. }
  36. catch (std::bad_alloc&)
  37. {
  38. assert(A::count == 0);
  39. }
  40. assert(globalMemCounter.checkOutstandingNewEq(0));
  41. }