]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_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 / nullptr_t_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 D, class A> shared_ptr(nullptr_t, 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     try
34     {
35         test_allocator<A>::throw_after = 0;
36         std::shared_ptr<A> p(nullptr, 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 }