From 092a57f5082146b6770f89839666b7545a0d27f0 Mon Sep 17 00:00:00 2001 From: Logan Smith Date: Thu, 20 Feb 2020 12:23:36 -0500 Subject: [PATCH] [libc++] Fix unqualified call to 'ref' inside shared_ptr(unique_ptr) This prevents unintended ADL: https://gcc.godbolt.org/z/EHw3Gy This issue was mentioned as an addendum in PR44398. Differential Revision: https://reviews.llvm.org/D74289 --- libcxx/include/memory | 2 +- .../util.smartptr.shared.const/unique_ptr.pass.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libcxx/include/memory b/libcxx/include/memory index 821f371eb0b0..4610bfe8dc43 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -4174,7 +4174,7 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, typedef __shared_ptr_pointer<_Yp*, reference_wrapper::type>, _AllocT > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT()); + __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT()); __enable_weak_this(__r.get(), __r.get()); } __r.release(); diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp index 41e64c6b431d..91716fca0574 100644 --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp @@ -49,6 +49,13 @@ void fn ( const std::shared_ptr &) { assert (false); } template void assert_deleter ( T * ) { assert(false); } +namespace adl { +struct D { + void operator()(int *) const {} +}; +void ref(D); +} + int main(int, char**) { { @@ -98,5 +105,11 @@ int main(int, char**) } #endif + { + adl::D d; + std::unique_ptr u(nullptr, d); + std::shared_ptr s = std::move(u); + } + return 0; }