diff options
author | Eric Fiselier <eric@efcs.ca> | 2017-05-10 19:35:49 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2017-05-10 19:35:49 +0000 |
commit | 1bc7a4b31e271f28dddd68fa2a81744714541e21 (patch) | |
tree | b4c143364e3f2f8c31da7d124cc22900a93683cf /include/memory | |
parent | f0346a566395620123e35d48da4fee038eb188da (diff) |
[libc++] Fix PR32979 - types with a private std::enable_shared_from_this base break shared_ptr
Summary:
This patch fixes bugs.llvm.org/PR32979.
[util.smartptr.shared.const] says:
> In the constructor definitions below, enables shared_from_this with p, for a pointer p of type Y*, means
> that if Y has an unambiguous and accessible base class that is a specialization of enable_shared_from_-
> this.
This means that libc++ needs to respect the access specifier of the base class, and not attempt to construct
and enabled_shared_from_this base if it is private. However access specifiers don't affect overload resolution
so our current implementation will attempt to construct the private base.
This patch uses SFINAE to correctly detect if the shared_ptr input has an accessible enable_shared_from_this
base class.
Reviewers: mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D33033
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@302709 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/memory')
-rw-r--r-- | include/memory | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/include/memory b/include/memory index 41ab01b46..bb1b41531 100644 --- a/include/memory +++ b/include/memory @@ -3924,7 +3924,10 @@ private: template <class _Yp, class _OrigPtr> _LIBCPP_INLINE_VISIBILITY - void + typename enable_if<is_convertible<_OrigPtr*, + const enable_shared_from_this<_Yp>* + >::value, + void>::type __enable_weak_this(const enable_shared_from_this<_Yp>* __e, _OrigPtr* __ptr) _NOEXCEPT { @@ -3943,6 +3946,7 @@ private: template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr; }; + template<class _Tp> inline _LIBCPP_CONSTEXPR |