Index: include/memory =================================================================== --- include/memory +++ include/memory @@ -3924,7 +3924,10 @@ template _LIBCPP_INLINE_VISIBILITY - void + typename enable_if* + >::value, + void>::type __enable_weak_this(const enable_shared_from_this<_Yp>* __e, _OrigPtr* __ptr) _NOEXCEPT { @@ -3943,6 +3946,7 @@ template friend class _LIBCPP_TEMPLATE_VIS weak_ptr; }; + template inline _LIBCPP_CONSTEXPR Index: test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -49,6 +49,11 @@ }; +struct PrivateBase : private std::enable_shared_from_this { + std::weak_ptr get_weak() { return weak_from_this(); } +}; + + int main() { { // https://bugs.llvm.org/show_bug.cgi?id=18843 @@ -74,6 +79,12 @@ assert(p == q); assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership } + { + typedef std::shared_ptr APtr; + typedef std::weak_ptr WeakAPtr; + APtr a1 = std::make_shared(); + 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: