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 10 // UNSUPPORTED: libcpp-no-exceptions 11 // UNSUPPORTED: sanitizer-new-delete 12 13 // <memory> 14 15 // shared_ptr 16 17 // template<class Y, class D> shared_ptr(Y* p, D d); 18 19 #include <memory> 20 #include <cassert> 21 #include <new> 22 #include <cstdlib> 23 24 #include "count_new.hpp" 25 #include "deleter_types.h" 26 27 struct A 28 { 29 static int count; 30 31 A() {++count;} 32 A(const A&) {++count;} 33 ~A() {--count;} 34 }; 35 36 int A::count = 0; 37 38 int main() 39 { 40 globalMemCounter.reset(); 41 A* ptr = new A; 42 globalMemCounter.throw_after = 0; 43 try 44 { 45 std::shared_ptr<A> p(ptr, test_deleter<A>(3)); 46 assert(false); 47 } 48 catch (std::bad_alloc&) 49 { 50 assert(A::count == 0); 51 assert(test_deleter<A>::count == 0); 52 assert(test_deleter<A>::dealloc_count == 1); 53 } 54 assert(globalMemCounter.checkOutstandingNewEq(0)); 55 } 56