cef/patch/patches/win_base_msvc_sandbox.patch
2020-03-04 19:31:54 -05:00

343 lines
13 KiB
Diff

diff --git base/containers/circular_deque.h base/containers/circular_deque.h
index 0d452b56bedd..bf42a9584488 100644
--- base/containers/circular_deque.h
+++ base/containers/circular_deque.h
@@ -14,7 +14,6 @@
#include "base/containers/vector_buffer.h"
#include "base/logging.h"
#include "base/macros.h"
-#include "base/stl_util.h"
#include "base/template_util.h"
// base::circular_deque is similar to std::deque. Unlike std::deque, the
@@ -522,15 +521,15 @@ class circular_deque {
return buffer_[i - right_size];
}
value_type& at(size_type i) {
- return const_cast<value_type&>(as_const(*this).at(i));
+ return const_cast<value_type&>(
+ const_cast<const circular_deque*>(this)->at(i));
}
- value_type& operator[](size_type i) {
- return const_cast<value_type&>(as_const(*this)[i]);
+ value_type& operator[](size_type i) { return at(i); }
+ const value_type& operator[](size_type i) const {
+ return const_cast<circular_deque*>(this)->at(i);
}
- const value_type& operator[](size_type i) const { return at(i); }
-
value_type& front() {
DCHECK(!empty());
return buffer_[begin_];
diff --git base/containers/flat_tree.h base/containers/flat_tree.h
index b7549dd5b0c6..89c75d70692e 100644
--- base/containers/flat_tree.h
+++ base/containers/flat_tree.h
@@ -10,7 +10,6 @@
#include <type_traits>
#include <vector>
-#include "base/stl_util.h"
#include "base/template_util.h"
namespace base {
@@ -341,6 +340,8 @@ class flat_tree {
const key_compare& key_comp_;
};
+ const flat_tree& as_const() { return *this; }
+
iterator const_cast_it(const_iterator c_it) {
auto distance = std::distance(cbegin(), c_it);
return std::next(begin(), distance);
@@ -776,7 +777,7 @@ template <class Key, class Value, class GetKeyFromValue, class KeyCompare>
template <typename K>
auto flat_tree<Key, Value, GetKeyFromValue, KeyCompare>::find(const K& key)
-> iterator {
- return const_cast_it(as_const(*this).find(key));
+ return const_cast_it(as_const().find(key));
}
template <class Key, class Value, class GetKeyFromValue, class KeyCompare>
@@ -799,7 +800,7 @@ template <class Key, class Value, class GetKeyFromValue, class KeyCompare>
template <typename K>
auto flat_tree<Key, Value, GetKeyFromValue, KeyCompare>::equal_range(
const K& key) -> std::pair<iterator, iterator> {
- auto res = as_const(*this).equal_range(key);
+ auto res = as_const().equal_range(key);
return {const_cast_it(res.first), const_cast_it(res.second)};
}
@@ -820,7 +821,7 @@ template <class Key, class Value, class GetKeyFromValue, class KeyCompare>
template <typename K>
auto flat_tree<Key, Value, GetKeyFromValue, KeyCompare>::lower_bound(
const K& key) -> iterator {
- return const_cast_it(as_const(*this).lower_bound(key));
+ return const_cast_it(as_const().lower_bound(key));
}
template <class Key, class Value, class GetKeyFromValue, class KeyCompare>
@@ -841,7 +842,7 @@ template <class Key, class Value, class GetKeyFromValue, class KeyCompare>
template <typename K>
auto flat_tree<Key, Value, GetKeyFromValue, KeyCompare>::upper_bound(
const K& key) -> iterator {
- return const_cast_it(as_const(*this).upper_bound(key));
+ return const_cast_it(as_const().upper_bound(key));
}
template <class Key, class Value, class GetKeyFromValue, class KeyCompare>
diff --git base/stl_util.h base/stl_util.h
index 83d86ad90d24..4edd1fb9e20b 100644
--- base/stl_util.h
+++ base/stl_util.h
@@ -158,16 +158,6 @@ constexpr const T* data(const std::array<T, N>& array) noexcept {
return !array.empty() ? &array[0] : nullptr;
}
-// C++14 implementation of C++17's std::as_const():
-// https://en.cppreference.com/w/cpp/utility/as_const
-template <typename T>
-constexpr std::add_const_t<T>& as_const(T& t) noexcept {
- return t;
-}
-
-template <typename T>
-void as_const(const T&& t) = delete;
-
// Returns a const reference to the underlying container of a container adapter.
// Works for std::priority_queue, std::queue, and std::stack.
template <class A>
diff --git base/values.cc base/values.cc
index fbc859c6518d..95e8fc815067 100644
--- base/values.cc
+++ base/values.cc
@@ -24,20 +24,6 @@
namespace base {
-// base::Value must be standard layout to guarantee that writing to
-// |bool_type_| then reading |type_| is defined behaviour. See:
-//
-// [class.union]:
-// If a standard-layout union contains several standard-layout structs that
-// share a common initial sequence (9.2), and if an object of this
-// standard-layout union type contains one of the standard-layout structs,
-// it is permitted to inspect the common initial sequence of any of
-// standard-layout struct members;
-//
-static_assert(std::is_standard_layout<Value>::value,
- "base::Value should be a standard-layout C++ class in order "
- "to avoid undefined behaviour in its implementation!");
-
static_assert(sizeof(Value::DoubleStorage) == sizeof(double),
"The double and DoubleStorage types should have the same size");
@@ -433,7 +419,7 @@ void Value::ClearList() {
}
Value* Value::FindKey(StringPiece key) {
- return const_cast<Value*>(as_const(*this).FindKey(key));
+ return const_cast<Value*>(static_cast<const Value*>(this)->FindKey(key));
}
const Value* Value::FindKey(StringPiece key) const {
@@ -445,7 +431,8 @@ const Value* Value::FindKey(StringPiece key) const {
}
Value* Value::FindKeyOfType(StringPiece key, Type type) {
- return const_cast<Value*>(as_const(*this).FindKeyOfType(key, type));
+ return const_cast<Value*>(
+ static_cast<const Value*>(this)->FindKeyOfType(key, type));
}
const Value* Value::FindKeyOfType(StringPiece key, Type type) const {
@@ -569,7 +556,7 @@ Optional<Value> Value::ExtractKey(StringPiece key) {
}
Value* Value::FindPath(StringPiece path) {
- return const_cast<Value*>(as_const(*this).FindPath(path));
+ return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path));
}
const Value* Value::FindPath(StringPiece path) const {
@@ -584,7 +571,8 @@ const Value* Value::FindPath(StringPiece path) const {
}
Value* Value::FindPathOfType(StringPiece path, Type type) {
- return const_cast<Value*>(as_const(*this).FindPathOfType(path, type));
+ return const_cast<Value*>(
+ const_cast<const Value*>(this)->FindPathOfType(path, type));
}
const Value* Value::FindPathOfType(StringPiece path, Type type) const {
@@ -627,7 +615,8 @@ const std::string* Value::FindStringPath(StringPiece path) const {
}
std::string* Value::FindStringPath(StringPiece path) {
- return const_cast<std::string*>(as_const(*this).FindStringPath(path));
+ return const_cast<std::string*>(
+ static_cast<const Value*>(this)->FindStringPath(path));
}
const Value::BlobStorage* Value::FindBlobPath(StringPiece path) const {
@@ -713,11 +702,11 @@ Optional<Value> Value::ExtractPath(StringPiece path) {
// DEPRECATED METHODS
Value* Value::FindPath(std::initializer_list<StringPiece> path) {
- return const_cast<Value*>(as_const(*this).FindPath(path));
+ return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path));
}
Value* Value::FindPath(span<const StringPiece> path) {
- return const_cast<Value*>(as_const(*this).FindPath(path));
+ return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path));
}
const Value* Value::FindPath(std::initializer_list<StringPiece> path) const {
@@ -736,11 +725,13 @@ const Value* Value::FindPath(span<const StringPiece> path) const {
Value* Value::FindPathOfType(std::initializer_list<StringPiece> path,
Type type) {
- return const_cast<Value*>(as_const(*this).FindPathOfType(path, type));
+ return const_cast<Value*>(
+ const_cast<const Value*>(this)->FindPathOfType(path, type));
}
Value* Value::FindPathOfType(span<const StringPiece> path, Type type) {
- return const_cast<Value*>(as_const(*this).FindPathOfType(path, type));
+ return const_cast<Value*>(
+ const_cast<const Value*>(this)->FindPathOfType(path, type));
}
const Value* Value::FindPathOfType(std::initializer_list<StringPiece> path,
@@ -902,7 +893,7 @@ bool Value::GetAsString(string16* out_value) const {
bool Value::GetAsString(const Value** out_value) const {
if (out_value && is_string()) {
- *out_value = this;
+ *out_value = static_cast<const Value*>(this);
return true;
}
return is_string();
@@ -1300,7 +1291,9 @@ bool DictionaryValue::Get(StringPiece path,
}
bool DictionaryValue::Get(StringPiece path, Value** out_value) {
- return as_const(*this).Get(path, const_cast<const Value**>(out_value));
+ return static_cast<const DictionaryValue&>(*this).Get(
+ path,
+ const_cast<const Value**>(out_value));
}
bool DictionaryValue::GetBoolean(StringPiece path, bool* bool_value) const {
@@ -1373,7 +1366,8 @@ bool DictionaryValue::GetBinary(StringPiece path,
}
bool DictionaryValue::GetBinary(StringPiece path, Value** out_value) {
- return as_const(*this).GetBinary(path, const_cast<const Value**>(out_value));
+ return static_cast<const DictionaryValue&>(*this).GetBinary(
+ path, const_cast<const Value**>(out_value));
}
bool DictionaryValue::GetDictionary(StringPiece path,
@@ -1391,8 +1385,9 @@ bool DictionaryValue::GetDictionary(StringPiece path,
bool DictionaryValue::GetDictionary(StringPiece path,
DictionaryValue** out_value) {
- return as_const(*this).GetDictionary(
- path, const_cast<const DictionaryValue**>(out_value));
+ return static_cast<const DictionaryValue&>(*this).GetDictionary(
+ path,
+ const_cast<const DictionaryValue**>(out_value));
}
bool DictionaryValue::GetList(StringPiece path,
@@ -1409,8 +1404,9 @@ bool DictionaryValue::GetList(StringPiece path,
}
bool DictionaryValue::GetList(StringPiece path, ListValue** out_value) {
- return as_const(*this).GetList(path,
- const_cast<const ListValue**>(out_value));
+ return static_cast<const DictionaryValue&>(*this).GetList(
+ path,
+ const_cast<const ListValue**>(out_value));
}
bool DictionaryValue::GetWithoutPathExpansion(StringPiece key,
@@ -1427,8 +1423,9 @@ bool DictionaryValue::GetWithoutPathExpansion(StringPiece key,
bool DictionaryValue::GetWithoutPathExpansion(StringPiece key,
Value** out_value) {
- return as_const(*this).GetWithoutPathExpansion(
- key, const_cast<const Value**>(out_value));
+ return static_cast<const DictionaryValue&>(*this).GetWithoutPathExpansion(
+ key,
+ const_cast<const Value**>(out_value));
}
bool DictionaryValue::GetBooleanWithoutPathExpansion(StringPiece key,
@@ -1494,8 +1491,11 @@ bool DictionaryValue::GetDictionaryWithoutPathExpansion(
bool DictionaryValue::GetDictionaryWithoutPathExpansion(
StringPiece key,
DictionaryValue** out_value) {
- return as_const(*this).GetDictionaryWithoutPathExpansion(
- key, const_cast<const DictionaryValue**>(out_value));
+ const DictionaryValue& const_this =
+ static_cast<const DictionaryValue&>(*this);
+ return const_this.GetDictionaryWithoutPathExpansion(
+ key,
+ const_cast<const DictionaryValue**>(out_value));
}
bool DictionaryValue::GetListWithoutPathExpansion(
@@ -1514,8 +1514,10 @@ bool DictionaryValue::GetListWithoutPathExpansion(
bool DictionaryValue::GetListWithoutPathExpansion(StringPiece key,
ListValue** out_value) {
- return as_const(*this).GetListWithoutPathExpansion(
- key, const_cast<const ListValue**>(out_value));
+ return
+ static_cast<const DictionaryValue&>(*this).GetListWithoutPathExpansion(
+ key,
+ const_cast<const ListValue**>(out_value));
}
bool DictionaryValue::Remove(StringPiece path,
@@ -1645,7 +1647,9 @@ bool ListValue::Get(size_t index, const Value** out_value) const {
}
bool ListValue::Get(size_t index, Value** out_value) {
- return as_const(*this).Get(index, const_cast<const Value**>(out_value));
+ return static_cast<const ListValue&>(*this).Get(
+ index,
+ const_cast<const Value**>(out_value));
}
bool ListValue::GetBoolean(size_t index, bool* bool_value) const {
@@ -1702,8 +1706,9 @@ bool ListValue::GetDictionary(size_t index,
}
bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) {
- return as_const(*this).GetDictionary(
- index, const_cast<const DictionaryValue**>(out_value));
+ return static_cast<const ListValue&>(*this).GetDictionary(
+ index,
+ const_cast<const DictionaryValue**>(out_value));
}
bool ListValue::GetList(size_t index, const ListValue** out_value) const {
@@ -1719,8 +1724,9 @@ bool ListValue::GetList(size_t index, const ListValue** out_value) const {
}
bool ListValue::GetList(size_t index, ListValue** out_value) {
- return as_const(*this).GetList(index,
- const_cast<const ListValue**>(out_value));
+ return static_cast<const ListValue&>(*this).GetList(
+ index,
+ const_cast<const ListValue**>(out_value));
}
bool ListValue::Remove(size_t index, std::unique_ptr<Value>* out_value) {