]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / util.smartptr / util.smartptr.shared / util.smartptr.shared.const / pointer_deleter_allocator_throw.pass.cpp
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 // <memory>
12
13 // template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
14
15 #include <memory>
16 #include <cassert>
17 #include "../test_deleter.h"
18 #include "test_allocator.h"
19
20 struct A
21 {
22     static int count;
23
24     A() {++count;}
25     A(const A&) {++count;}
26     ~A() {--count;}
27 };
28
29 int A::count = 0;
30
31 int main()
32 {
33     A* ptr = new A;
34     try
35     {
36         test_allocator<A>::throw_after = 0;
37         std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
38         assert(false);
39     }
40     catch (std::bad_alloc&)
41     {
42         assert(A::count == 0);
43         assert(test_deleter<A>::count == 0);
44         assert(test_deleter<A>::dealloc_count == 1);
45         assert(test_allocator<A>::count == 0);
46         assert(test_allocator<A>::alloc_count == 0);
47     }
48 }