]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_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_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 // UNSUPPORTED: sanitizer-new-delete
12
13 // <memory>
14
15 // shared_ptr
16
17 // template<class Y, class D> shared_ptr(Y* p, D d);
18
19 #include <memory>
20 #include <cassert>
21 #include <new>
22 #include <cstdlib>
23
24 #include "count_new.hpp"
25 #include "../test_deleter.h"
26
27 struct A
28 {
29     static int count;
30
31     A() {++count;}
32     A(const A&) {++count;}
33     ~A() {--count;}
34 };
35
36 int A::count = 0;
37
38 int main()
39 {
40     A* ptr = new A;
41     globalMemCounter.throw_after = 0;
42     try
43     {
44         std::shared_ptr<A> p(ptr, test_deleter<A>(3));
45         assert(false);
46     }
47     catch (std::bad_alloc&)
48     {
49         assert(A::count == 0);
50         assert(test_deleter<A>::count == 0);
51         assert(test_deleter<A>::dealloc_count == 1);
52     }
53     assert(globalMemCounter.checkOutstandingNewEq(0));
54 }