pointer_deleter_allocator_throw.pass.cpp revision 1b92188a82b01e76ac6e8ad5f997293c2a078adc
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// <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