diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fxcrt/cfx_maybe_owned.h | 2 | ||||
-rw-r--r-- | core/fxcrt/cfx_retain_ptr.h | 2 | ||||
-rw-r--r-- | core/fxcrt/cfx_retain_ptr_unittest.cpp | 24 | ||||
-rw-r--r-- | core/fxcrt/cfx_weak_ptr.h | 2 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_bstring.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_wstring.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/fx_string.h | 4 |
7 files changed, 31 insertions, 7 deletions
diff --git a/core/fxcrt/cfx_maybe_owned.h b/core/fxcrt/cfx_maybe_owned.h index 92b1c1c242..8b08d9be37 100644 --- a/core/fxcrt/cfx_maybe_owned.h +++ b/core/fxcrt/cfx_maybe_owned.h @@ -25,7 +25,7 @@ class CFX_MaybeOwned { : m_pOwnedObj(std::move(ptr)), m_pObj(m_pOwnedObj.get()) {} CFX_MaybeOwned(const CFX_MaybeOwned& that) = delete; - CFX_MaybeOwned(CFX_MaybeOwned&& that) + CFX_MaybeOwned(CFX_MaybeOwned&& that) noexcept : m_pOwnedObj(that.m_pOwnedObj.release()), m_pObj(that.m_pObj) { that.m_pObj = nullptr; } diff --git a/core/fxcrt/cfx_retain_ptr.h b/core/fxcrt/cfx_retain_ptr.h index 5db384f334..32a77c5a6c 100644 --- a/core/fxcrt/cfx_retain_ptr.h +++ b/core/fxcrt/cfx_retain_ptr.h @@ -22,7 +22,7 @@ class CFX_RetainPtr { CFX_RetainPtr() {} CFX_RetainPtr(const CFX_RetainPtr& that) : CFX_RetainPtr(that.Get()) {} - CFX_RetainPtr(CFX_RetainPtr&& that) { Swap(that); } + CFX_RetainPtr(CFX_RetainPtr&& that) noexcept { Swap(that); } // Deliberately implicit to allow returning nullptrs. CFX_RetainPtr(std::nullptr_t ptr) {} diff --git a/core/fxcrt/cfx_retain_ptr_unittest.cpp b/core/fxcrt/cfx_retain_ptr_unittest.cpp index f097b4b28c..fc0309467c 100644 --- a/core/fxcrt/cfx_retain_ptr_unittest.cpp +++ b/core/fxcrt/cfx_retain_ptr_unittest.cpp @@ -5,6 +5,7 @@ #include "core/fxcrt/cfx_retain_ptr.h" #include <utility> +#include <vector> #include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" @@ -275,3 +276,26 @@ TEST(fxcrt, RetainPtrMakeRetained) { } EXPECT_TRUE(ptr->HasOneRef()); } + +TEST(fxcrt, RetainPtrVectorMove) { + // Proves move ctor is selected by std::vector over copy/delete, this + // may require the ctor to be marked "noexcept". + PseudoRetainable obj; + { + CFX_RetainPtr<PseudoRetainable> ptr(&obj); + std::vector<CFX_RetainPtr<PseudoRetainable>> vec1; + vec1.push_back(std::move(ptr)); + EXPECT_EQ(1, obj.retain_count()); + EXPECT_EQ(0, obj.release_count()); + + std::vector<CFX_RetainPtr<PseudoRetainable>> vec2 = std::move(vec1); + EXPECT_EQ(1, obj.retain_count()); + EXPECT_EQ(0, obj.release_count()); + + vec2.resize(4096); + EXPECT_EQ(1, obj.retain_count()); + EXPECT_EQ(0, obj.release_count()); + } + EXPECT_EQ(1, obj.retain_count()); + EXPECT_EQ(1, obj.release_count()); +} diff --git a/core/fxcrt/cfx_weak_ptr.h b/core/fxcrt/cfx_weak_ptr.h index 43ae5b881d..4aca1c3218 100644 --- a/core/fxcrt/cfx_weak_ptr.h +++ b/core/fxcrt/cfx_weak_ptr.h @@ -19,7 +19,7 @@ class CFX_WeakPtr { public: CFX_WeakPtr() {} CFX_WeakPtr(const CFX_WeakPtr& that) : m_pHandle(that.m_pHandle) {} - CFX_WeakPtr(CFX_WeakPtr&& that) { Swap(that); } + CFX_WeakPtr(CFX_WeakPtr&& that) noexcept { Swap(that); } explicit CFX_WeakPtr(std::unique_ptr<T, D> pObj) : m_pHandle(new Handle(std::move(pObj))) {} diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp index f049b14c3a..a4e491f4d3 100644 --- a/core/fxcrt/fx_basic_bstring.cpp +++ b/core/fxcrt/fx_basic_bstring.cpp @@ -103,7 +103,7 @@ CFX_ByteString::CFX_ByteString() {} CFX_ByteString::CFX_ByteString(const CFX_ByteString& other) : m_pData(other.m_pData) {} -CFX_ByteString::CFX_ByteString(CFX_ByteString&& other) { +CFX_ByteString::CFX_ByteString(CFX_ByteString&& other) noexcept { m_pData.Swap(other.m_pData); } diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp index 384b0b0086..5cb6a57181 100644 --- a/core/fxcrt/fx_basic_wstring.cpp +++ b/core/fxcrt/fx_basic_wstring.cpp @@ -72,7 +72,7 @@ CFX_WideString::CFX_WideString() {} CFX_WideString::CFX_WideString(const CFX_WideString& other) : m_pData(other.m_pData) {} -CFX_WideString::CFX_WideString(CFX_WideString&& other) { +CFX_WideString::CFX_WideString(CFX_WideString&& other) noexcept { m_pData.Swap(other.m_pData); } diff --git a/core/fxcrt/fx_string.h b/core/fxcrt/fx_string.h index 12304eb452..494633e41d 100644 --- a/core/fxcrt/fx_string.h +++ b/core/fxcrt/fx_string.h @@ -36,7 +36,7 @@ class CFX_ByteString { CFX_ByteString(); CFX_ByteString(const CFX_ByteString& other); - CFX_ByteString(CFX_ByteString&& other); + CFX_ByteString(CFX_ByteString&& other) noexcept; // Deliberately implicit to avoid calling on every string literal. // NOLINTNEXTLINE(runtime/explicit) @@ -235,7 +235,7 @@ class CFX_WideString { CFX_WideString(); CFX_WideString(const CFX_WideString& other); - CFX_WideString(CFX_WideString&& other); + CFX_WideString(CFX_WideString&& other) noexcept; // Deliberately implicit to avoid calling on every string literal. // NOLINTNEXTLINE(runtime/explicit) |