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 | // template<class Y> explicit shared_ptr(Y* p); |
15 | |
16 | |
17 | #include <memory> |
18 | #include <new> |
19 | #include <cstdlib> |
20 | #include <cassert> |
21 | |
22 | #include "count_new.h" |
23 | |
24 | #include "test_macros.h" |
25 | |
26 | struct A |
27 | { |
28 | static int count; |
29 | |
30 | A() {++count;} |
31 | A(const A&) {++count;} |
32 | ~A() {--count;} |
33 | }; |
34 | |
35 | int A::count = 0; |
36 | |
37 | |
38 | int main(int, char**) |
39 | { |
40 | globalMemCounter.reset(); |
41 | A* ptr = new A; |
42 | assert(A::count == 1); |
43 | globalMemCounter.throw_after = 0; |
44 | try |
45 | { |
46 | std::shared_ptr<A> p(ptr); |
47 | assert(false); |
48 | } |
49 | catch (std::bad_alloc&) |
50 | { |
51 | assert(A::count == 0); |
52 | } |
53 | assert(globalMemCounter.checkOutstandingNewEq(0)); |
54 | |
55 | return 0; |
56 | } |
57 | |