pointer_deleter_allocator_throw.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===// 2// 3// ��������������������The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <memory> 11 12// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); 13 14#include <memory> 15#include <cassert> 16#include "../test_deleter.h" 17#include "../test_allocator.h" 18 19struct A 20{ 21 static int count; 22 23 A() {++count;} 24 A(const A&) {++count;} 25 ~A() {--count;} 26}; 27 28int A::count = 0; 29 30int main() 31{ 32 A* ptr = new A; 33 try 34 { 35 test_allocator<A>::throw_after = 0; 36 std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5)); 37 assert(false); 38 } 39 catch (std::bad_alloc&) 40 { 41 assert(A::count == 0); 42 assert(test_deleter<A>::count == 0); 43 assert(test_deleter<A>::dealloc_count == 1); 44 assert(test_allocator<A>::count == 0); 45 assert(test_allocator<A>::alloc_count == 0); 46 } 47} 48