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 | // <memory> |
10 | |
11 | // shared_ptr |
12 | |
13 | // template<class D> shared_ptr(nullptr_t, D d); |
14 | |
15 | #include <memory> |
16 | #include <cassert> |
17 | #include "test_macros.h" |
18 | #include "deleter_types.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(int, char**) |
32 | { |
33 | { |
34 | std::shared_ptr<A> p(nullptr, test_deleter<A>(3)); |
35 | assert(A::count == 0); |
36 | assert(p.use_count() == 1); |
37 | assert(p.get() == 0); |
38 | assert(test_deleter<A>::count == 1); |
39 | assert(test_deleter<A>::dealloc_count == 0); |
40 | #ifndef TEST_HAS_NO_RTTI |
41 | test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p); |
42 | assert(d); |
43 | assert(d->state() == 3); |
44 | #endif |
45 | } |
46 | assert(A::count == 0); |
47 | assert(test_deleter<A>::count == 0); |
48 | assert(test_deleter<A>::dealloc_count == 1); |
49 | |
50 | { |
51 | std::shared_ptr<A const> p(nullptr, test_deleter<A const>(3)); |
52 | assert(p.get() == nullptr); |
53 | } |
54 | |
55 | return 0; |
56 | } |
57 | |