Author: Jonas Devlieghere Date: 2025-11-21T04:29:16Z New Revision: cf837e2ffe7b89a861f7145235190a1a000f3559
URL: https://github.com/llvm/llvm-project/commit/cf837e2ffe7b89a861f7145235190a1a000f3559 DIFF: https://github.com/llvm/llvm-project/commit/cf837e2ffe7b89a861f7145235190a1a000f3559.diff LOG: [lldb] Add assert to NonNullSharedPtr move constructor (#168979) As suggested by Augusto, add an assert to the NonNullSharedPtr move constructor. Added: Modified: lldb/include/lldb/Utility/NonNullSharedPtr.h Removed: ################################################################################ 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 <typename T> class NonNullSharedPtr : private std::shared_ptr<T> { public: NonNullSharedPtr(const std::shared_ptr<T> &t) : Base(t ? t : std::make_shared<T>()) { - assert(t && "NonNullSharedPtr initialized from NULL shared_ptr"); + assert(t && "NonNullSharedPtr constructed from nullptr"); } - NonNullSharedPtr(std::shared_ptr<T> &&t) - : Base(t ? std::move(t) : std::make_shared<T>()) { - // Can't assert on t as it's been moved-from. + NonNullSharedPtr(std::shared_ptr<T> &&t) : Base(std::move(t)) { + const auto b = static_cast<bool>(*this); + assert(b && "NonNullSharedPtr constructed from nullptr"); + if (!b) + Base::operator=(std::make_shared<T>()); } NonNullSharedPtr(const NonNullSharedPtr &other) : Base(other) {} _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
