diff --git a/lldb/include/lldb/Utility/NonNullSharedPtr.h b/lldb/include/lldb/Utility/NonNullSharedPtr.h index 7e12ce72c6238..d084e79759d1b 100644 --- a/lldb/include/lldb/Utility/NonNullSharedPtr.h +++ b/lldb/include/lldb/Utility/NonNullSharedPtr.h @@ -29,12 +29,14 @@ template class NonNullSharedPtr : private std::shared_ptr { public: NonNullSharedPtr(const std::shared_ptr &t) : Base(t ? t : std::make_shared()) { - assert(t && "NonNullSharedPtr initialized from NULL shared_ptr"); + assert(t && "NonNullSharedPtr constructed from nullptr"); } - NonNullSharedPtr(std::shared_ptr &&t) - : Base(t ? std::move(t) : std::make_shared()) { - // Can't assert on t as it's been moved-from. + NonNullSharedPtr(std::shared_ptr &&t) : Base(std::move(t)) { + const auto b = static_cast(*this); + assert(b && "NonNullSharedPtr constructed from nullptr"); + if (!b) + Base::operator=(std::make_shared()); } NonNullSharedPtr(const NonNullSharedPtr &other) : Base(other) {}