pointer_throw.pass.cpp (1021B)
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 // template<class Y> explicit shared_ptr(Y* p); 16 17 18 #include <memory> 19 #include <new> 20 #include <cstdlib> 21 #include <cassert> 22 23 #include "count_new.hpp" 24 25 struct A 26 { 27 static int count; 28 29 A() {++count;} 30 A(const A&) {++count;} 31 ~A() {--count;} 32 }; 33 34 int A::count = 0; 35 36 37 int main() 38 { 39 A* ptr = new A; 40 assert(A::count == 1); 41 globalMemCounter.throw_after = 0; 42 try 43 { 44 std::shared_ptr<A> p(ptr); 45 assert(false); 46 } 47 catch (std::bad_alloc&) 48 { 49 assert(A::count == 0); 50 } 51 assert(globalMemCounter.checkOutstandingNewEq(0)); 52 }