summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-28 14:09:43 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-28 21:28:39 +0000
commit3bb57514867a2bd10ba535e0b06de566a58d8085 (patch)
tree8c3019986ee23a0bec05955f861cee3b73b3770d
parent022ded02d2c23a8d043bbcb3d3f37dab12636759 (diff)
downloadpdfium-3bb57514867a2bd10ba535e0b06de566a58d8085.tar.xz
Ensure that CFX_RetainPtr move ctor is used by std::vector.
Add a test for one of our types that fails unless this is the case. Mark all our other move ctors as |noexcept|. Change-Id: Ib106f219183d5abf94504af420a43c94b8f40e22 Reviewed-on: https://pdfium-review.googlesource.com/3251 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--BUILD.gn5
-rw-r--r--core/fxcrt/cfx_maybe_owned.h2
-rw-r--r--core/fxcrt/cfx_retain_ptr.h2
-rw-r--r--core/fxcrt/cfx_retain_ptr_unittest.cpp24
-rw-r--r--core/fxcrt/cfx_weak_ptr.h2
-rw-r--r--core/fxcrt/fx_basic_bstring.cpp2
-rw-r--r--core/fxcrt/fx_basic_wstring.cpp2
-rw-r--r--core/fxcrt/fx_string.h4
8 files changed, 35 insertions, 8 deletions
diff --git a/BUILD.gn b/BUILD.gn
index d327c6093f..6d383510b4 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -79,7 +79,10 @@ config("pdfium_core_config") {
}
}
if (is_win) {
- cflags += [ "/wd4267" ]
+ cflags += [
+ "/wd4267",
+ "/wd4577",
+ ]
}
}
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)