diff options
Diffstat (limited to 'libcxx')
| -rw-r--r-- | libcxx/include/memory | 6 | ||||
| -rw-r--r-- | libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp | 11 |
2 files changed, 16 insertions, 1 deletions
diff --git a/libcxx/include/memory b/libcxx/include/memory index 41ab01b46f7..bb1b415311d 100644 --- a/libcxx/include/memory +++ b/libcxx/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 diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp index 5a0d9259c11..5124e025253 100644 --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -49,6 +49,11 @@ struct Bar : public Foo { }; +struct PrivateBase : private std::enable_shared_from_this<PrivateBase> { + std::weak_ptr<PrivateBase> get_weak() { return weak_from_this(); } +}; + + int main() { { // https://bugs.llvm.org/show_bug.cgi?id=18843 @@ -74,6 +79,12 @@ int main() assert(p == q); assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership } + { + typedef std::shared_ptr<PrivateBase> APtr; + typedef std::weak_ptr<PrivateBase> WeakAPtr; + APtr a1 = std::make_shared<PrivateBase>(); + assert(a1.use_count() == 1); + } // Test LWG issue 2529. Only reset '__weak_ptr_' when it's already expired. // http://cplusplus.github.io/LWG/lwg-active.html#2529. // Test two different ways: |

