//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // UNSUPPORTED: c++03, c++11, c++14 // template class shared_ptr // shared_ptr(weak_ptr) -> shared_ptr // shared_ptr(unique_ptr) -> shared_ptr #include #include #include "test_macros.h" struct A {}; struct D { void operator()(A const* ptr) const { delete ptr; } }; int main(int, char**) { { std::shared_ptr s0(new A); std::weak_ptr w = s0; auto s = std::shared_ptr(w); ASSERT_SAME_TYPE(decltype(s), std::shared_ptr); assert(s0.use_count() == 2); assert(s.use_count() == 2); assert(s0.get() == s.get()); } { std::shared_ptr s0(new A); std::weak_ptr w = s0; auto s = std::shared_ptr(w); ASSERT_SAME_TYPE(decltype(s), std::shared_ptr); assert(s0.use_count() == 2); assert(s.use_count() == 2); assert(s0.get() == s.get()); } { std::unique_ptr u(new A); A* uPointee = u.get(); std::shared_ptr s = std::move(u); ASSERT_SAME_TYPE(decltype(s), std::shared_ptr); assert(u == nullptr); assert(s.get() == uPointee); } { std::unique_ptr u(new A); A const* uPointee = u.get(); std::shared_ptr s = std::move(u); ASSERT_SAME_TYPE(decltype(s), std::shared_ptr); assert(u == nullptr); assert(s.get() == uPointee); } { std::unique_ptr u(new A, D{}); A* uPointee = u.get(); std::shared_ptr s(std::move(u)); ASSERT_SAME_TYPE(decltype(s), std::shared_ptr); assert(u == nullptr); assert(s.get() == uPointee); } { std::unique_ptr u(new A, D{}); A const* uPointee = u.get(); std::shared_ptr s(std::move(u)); ASSERT_SAME_TYPE(decltype(s), std::shared_ptr); assert(u == nullptr); assert(s.get() == uPointee); } return 0; }