1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<class Y> explicit shared_ptr(auto_ptr<Y>&& r);
13 // REQUIRES: c++03 || c++11 || c++14
14 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
21 #include "test_macros.h"
22 #include "count_new.h"
29 B(const B
&) {++count
;}
30 virtual ~B() {--count
;}
41 A(const A
& other
) : B(other
) {++count
;}
49 globalMemCounter
.reset();
51 std::auto_ptr
<A
> ptr(new A
);
52 A
* raw_ptr
= ptr
.get();
53 std::shared_ptr
<B
> p(std::move(ptr
));
54 assert(A::count
== 1);
55 assert(B::count
== 1);
56 assert(p
.use_count() == 1);
57 assert(p
.get() == raw_ptr
);
58 assert(ptr
.get() == 0);
60 assert(A::count
== 0);
61 assert(globalMemCounter
.checkOutstandingNewEq(0));
63 globalMemCounter
.reset();
65 std::auto_ptr
<A
const> ptr(new A
);
66 A
const* raw_ptr
= ptr
.get();
67 std::shared_ptr
<B
const> p(std::move(ptr
));
68 assert(A::count
== 1);
69 assert(B::count
== 1);
70 assert(p
.use_count() == 1);
71 assert(p
.get() == raw_ptr
);
72 assert(ptr
.get() == 0);
74 assert(A::count
== 0);
75 assert(globalMemCounter
.checkOutstandingNewEq(0));
77 #if !defined(TEST_HAS_NO_EXCEPTIONS) && !defined(DISABLE_NEW_COUNT)
79 std::auto_ptr
<A
> ptr(new A
);
80 A
* raw_ptr
= ptr
.get();
81 globalMemCounter
.throw_after
= 0;
84 std::shared_ptr
<B
> p(std::move(ptr
));
89 assert(A::count
== 1);
90 assert(B::count
== 1);
91 assert(ptr
.get() == raw_ptr
);
94 assert(A::count
== 0);
95 assert(globalMemCounter
.checkOutstandingNewEq(0));
96 #endif // !defined(TEST_HAS_NO_EXCEPTIONS) && !defined(DISABLE_NEW_COUNT)