Index: libcxx/include/memory =================================================================== --- libcxx/include/memory +++ libcxx/include/memory @@ -443,6 +443,11 @@ template bool owner_before(weak_ptr const& b) const noexcept; }; +template +shared_ptr(weak_ptr) -> shared_ptr; +template +shared_ptr(unique_ptr) -> shared_ptr; + // shared_ptr comparisons: template bool operator==(shared_ptr const& a, shared_ptr const& b) noexcept; @@ -541,6 +546,9 @@ template bool owner_before(weak_ptr const& b) const noexcept; }; +template +weak_ptr(shared_ptr) -> weak_ptr; + // weak_ptr specialized algorithms: template void swap(weak_ptr& a, weak_ptr& b) noexcept; @@ -3923,6 +3931,12 @@ template friend class _LIBCPP_TEMPLATE_VIS weak_ptr; }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template +shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; +template +shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>; +#endif template inline @@ -4731,6 +4745,11 @@ template friend class _LIBCPP_TEMPLATE_VIS shared_ptr; }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template +weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>; +#endif + template inline _LIBCPP_CONSTEXPR Index: libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + +// template class shared_ptr + +// shared_ptr(weak_ptr) -> shared_ptr +// shared_ptr(unique_ptr) -> shared_ptr + +#include + +struct A {}; + +int main(int, char**) +{ + { + auto s0 = std::shared_ptr(new A); + auto w = std::weak_ptr(s0); + auto s = std::shared_ptr(w); + } + { + auto u = std::unique_ptr(new A); + auto s = std::shared_ptr(std::move(u)); + } + + return 0; +} Index: libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_deduction.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_deduction.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + +// template class weak_ptr + +// weak_ptr(shared_ptr) -> weak_ptr + +#include + +struct A {}; + +int main(int, char**) +{ + auto s = std::shared_ptr(new A); + auto w = std::weak_ptr(s); + + return 0; +}