1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: no-exceptions |
10 | // UNSUPPORTED: sanitizer-new-delete |
11 | |
12 | // <memory> |
13 | |
14 | // shared_ptr |
15 | |
16 | // template<class Y, class D> shared_ptr(Y* p, D d); |
17 | |
18 | #include <memory> |
19 | #include <cassert> |
20 | #include <new> |
21 | #include <cstdlib> |
22 | |
23 | #include "count_new.h" |
24 | #include "test_macros.h" |
25 | #include "deleter_types.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(int, char**) |
39 | { |
40 | globalMemCounter.reset(); |
41 | A* ptr = new A; |
42 | globalMemCounter.throw_after = 0; |
43 | try |
44 | { |
45 | std::shared_ptr<A> p(ptr, test_deleter<A>(3)); |
46 | assert(false); |
47 | } |
48 | catch (std::bad_alloc&) |
49 | { |
50 | assert(A::count == 0); |
51 | assert(test_deleter<A>::count == 0); |
52 | assert(test_deleter<A>::dealloc_count == 1); |
53 | } |
54 | assert(globalMemCounter.checkOutstandingNewEq(0)); |
55 | |
56 | return 0; |
57 | } |
58 | |