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 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++03, c++11, c++14
12 // template<class T> class shared_ptr
14 // shared_ptr(weak_ptr<T>) -> shared_ptr<T>
15 // shared_ptr(unique_ptr<T>) -> shared_ptr<T>
21 #include "test_macros.h"
26 void operator()(A
const* ptr
) const
35 std::shared_ptr
<A
> s0(new A
);
36 std::weak_ptr
<A
> w
= s0
;
37 auto s
= std::shared_ptr(w
);
38 ASSERT_SAME_TYPE(decltype(s
), std::shared_ptr
<A
>);
39 assert(s0
.use_count() == 2);
40 assert(s
.use_count() == 2);
41 assert(s0
.get() == s
.get());
44 std::shared_ptr
<A
const> s0(new A
);
45 std::weak_ptr
<A
const> w
= s0
;
46 auto s
= std::shared_ptr(w
);
47 ASSERT_SAME_TYPE(decltype(s
), std::shared_ptr
<A
const>);
48 assert(s0
.use_count() == 2);
49 assert(s
.use_count() == 2);
50 assert(s0
.get() == s
.get());
54 std::unique_ptr
<A
> u(new A
);
55 A
* uPointee
= u
.get();
56 std::shared_ptr s
= std::move(u
);
57 ASSERT_SAME_TYPE(decltype(s
), std::shared_ptr
<A
>);
59 assert(s
.get() == uPointee
);
62 std::unique_ptr
<A
const> u(new A
);
63 A
const* uPointee
= u
.get();
64 std::shared_ptr s
= std::move(u
);
65 ASSERT_SAME_TYPE(decltype(s
), std::shared_ptr
<A
const>);
67 assert(s
.get() == uPointee
);
71 std::unique_ptr
<A
, D
> u(new A
, D
{});
72 A
* uPointee
= u
.get();
73 std::shared_ptr
s(std::move(u
));
74 ASSERT_SAME_TYPE(decltype(s
), std::shared_ptr
<A
>);
76 assert(s
.get() == uPointee
);
79 std::unique_ptr
<A
const, D
> u(new A
, D
{});
80 A
const* uPointee
= u
.get();
81 std::shared_ptr
s(std::move(u
));
82 ASSERT_SAME_TYPE(decltype(s
), std::shared_ptr
<A
const>);
84 assert(s
.get() == uPointee
);