Windows: Fix cef_sandbox build error: call to 'as_const' is ambiguous.

See https://crbug.com/752720#c132 for details.
This commit is contained in:
Marshall Greenblatt 2020-02-18 15:15:32 -05:00
parent fb925e7aa5
commit e472228f29
3 changed files with 357 additions and 26 deletions

View File

@ -414,7 +414,12 @@ patches = [
# for the cef_sandbox build, and which is no longer required.
# https://bugs.chromium.org/p/chromium/issues/detail?id=646113#c173
# https://chromium.googlesource.com/chromium/src/+/2f28731c17
'name': 'base_value_646113',
#
# Windows: Revert "implement C++17's std::as_const" change which causes the
# cef_sandbox build to fail with "error: call to 'as_const' is ambiguous".
# https://bugs.chromium.org/p/chromium/issues/detail?id=752720#c132
# https://chromium.googlesource.com/chromium/src/+/9b751f0f4d
'name': 'win_base_msvc_sandbox',
},
{
# Restore WebView::SetResizeBackgroundColor() that was removed.

View File

@ -1,25 +0,0 @@
diff --git base/values.cc base/values.cc
index 66e8d39abf0b..2a3d7ebfd10e 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");

View File

@ -0,0 +1,351 @@
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 66e8d39abf0b..c6674c3b65fb 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");
@@ -428,7 +414,7 @@ bool Value::EraseListIter(ListStorage::const_iterator iter) {
}
bool Value::EraseListIter(CheckedContiguousConstIterator<Value> iter) {
- const auto offset = iter - as_const(*this).GetList().begin();
+ const auto offset = iter - static_cast<const Value*>(this)->GetList().begin();
return EraseListIter(list_.begin() + offset);
}
@@ -442,7 +428,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 {
@@ -454,7 +440,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 {
@@ -578,7 +565,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 {
@@ -593,7 +580,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 {
@@ -636,7 +624,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 {
@@ -722,11 +711,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 {
@@ -745,11 +734,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,
@@ -911,7 +902,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();
@@ -1309,7 +1300,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 {
@@ -1382,7 +1375,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,
@@ -1400,8 +1394,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,
@@ -1418,8 +1413,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,
@@ -1436,8 +1432,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,
@@ -1503,8 +1500,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(
@@ -1523,8 +1523,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,
@@ -1654,7 +1656,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 {
@@ -1711,8 +1715,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 {
@@ -1728,8 +1733,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) {