From c41133728d1a4197b8d0a366854b73d161788d20 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 19 Jun 2015 15:54:13 +0000 Subject: [PATCH] Fix PR#18843. Thanks to Howard for the fix git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@240136 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/memory | 5 ++++- .../util.smartptr.enab/enable_shared_from_this.pass.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/memory b/include/memory index 03897b1c..4c3a18c9 100644 --- a/include/memory +++ b/include/memory @@ -4073,7 +4073,10 @@ private: __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT { if (__e) - __e->__weak_this_ = *this; + { + __e->__weak_this_.__ptr_ = const_cast<_Yp*>(static_cast(__e)); + __e->__weak_this_.__cntrl_ = __cntrl_; + } } _LIBCPP_INLINE_VISIBILITY diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp index 58686d68..77af13fa 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -34,6 +34,10 @@ struct Z : Y {}; int main() { + { // https://llvm.org/bugs/show_bug.cgi?id=18843 + std::shared_ptr t1(new T); + std::shared_ptr t2(std::make_shared()); + } { std::shared_ptr p(new Z); std::shared_ptr q = p->shared_from_this();