Give UnownedPtr<> a move ctor and move assign operator. Otherwise, the examples added to the unit test will trip an incorrect asssertion. Change-Id: I1dc85cfdf0937036c4493e43ee9dfac03ec38767 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/63156 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/unowned_ptr.h b/core/fxcrt/unowned_ptr.h index 7bbd937..5a8ee3d 100644 --- a/core/fxcrt/unowned_ptr.h +++ b/core/fxcrt/unowned_ptr.h
@@ -49,6 +49,7 @@ public: constexpr UnownedPtr() noexcept = default; constexpr UnownedPtr(const UnownedPtr& that) noexcept = default; + constexpr UnownedPtr(UnownedPtr&& that) noexcept : m_pObj(that.Release()) {} template <typename U> explicit constexpr UnownedPtr(U* pObj) noexcept : m_pObj(pObj) {} @@ -75,6 +76,12 @@ return *this; } + UnownedPtr& operator=(UnownedPtr&& that) noexcept { + if (*this != that) + Reset(that.Release()); + return *this; + } + bool operator==(const UnownedPtr& that) const { return Get() == that.Get(); } bool operator!=(const UnownedPtr& that) const { return !(*this == that); } bool operator<(const UnownedPtr& that) const {
diff --git a/core/fxcrt/unowned_ptr_unittest.cpp b/core/fxcrt/unowned_ptr_unittest.cpp index c125873..f1979ef 100644 --- a/core/fxcrt/unowned_ptr_unittest.cpp +++ b/core/fxcrt/unowned_ptr_unittest.cpp
@@ -114,6 +114,25 @@ } } +TEST(UnownedPtr, MoveCtorOk) { + UnownedPtr<Clink> outer; + { + auto owned = pdfium::MakeUnique<Clink>(); + outer = owned.get(); + UnownedPtr<Clink> inner(std::move(outer)); + } +} + +TEST(UnownedPtr, MoveAssignOk) { + UnownedPtr<Clink> outer; + { + auto owned = pdfium::MakeUnique<Clink>(); + outer = owned.get(); + UnownedPtr<Clink> inner; + inner = std::move(outer); + } +} + TEST(UnownedPtr, ReleaseNotOk) { #if defined(ADDRESS_SANITIZER) EXPECT_DEATH(ReleaseDangling(), "");