Revert "[libc] Breakup freelist_malloc into separate files" (#119749)
[llvm-project.git] / libcxx / test / std / utilities / memory / util.smartptr / util.smartptr.shared / util.smartptr.shared.const / deduction.pass.cpp
blob9b875e6668d50bb6f688469fa8be8e312f2f1e36
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 //===----------------------------------------------------------------------===//
9 // <memory>
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>
17 #include <memory>
18 #include <cassert>
19 #include <utility>
21 #include "test_macros.h"
23 struct A {};
25 struct D {
26 void operator()(A const* ptr) const
28 delete ptr;
32 int main(int, char**)
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>);
58 assert(u == nullptr);
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>);
66 assert(u == nullptr);
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>);
75 assert(u == nullptr);
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>);
83 assert(u == nullptr);
84 assert(s.get() == uPointee);
87 return 0;