40_minor_no_c++20_changes.patch (9508B)
1 # HG changeset patch 2 # User Bob Owen <bobowencode@gmail.com> 3 Minor reversions for changes that require c++20 support. 4 5 diff --git a/base/check_op.h b/base/check_op.h 6 --- a/base/check_op.h 7 +++ b/base/check_op.h 8 @@ -65,17 +65,17 @@ BASE_EXPORT char* StreamValToStr(const v 9 #ifdef __has_builtin 10 #define SUPPORTS_BUILTIN_ADDRESSOF (__has_builtin(__builtin_addressof)) 11 #else 12 #define SUPPORTS_BUILTIN_ADDRESSOF 0 13 #endif 14 15 template <typename T> 16 inline std::enable_if_t< 17 - base::internal::SupportsOstreamOperator<const T&> && 18 + base::internal::SupportsOstreamOperator<const T&>::value && 19 !std::is_function_v<typename std::remove_pointer<T>::type>, 20 char*> 21 CheckOpValueStr(const T& v) { 22 auto f = [](std::ostream& s, const void* p) { 23 s << *reinterpret_cast<const T*>(p); 24 }; 25 26 // operator& might be overloaded, so do the std::addressof dance. 27 @@ -90,18 +90,19 @@ CheckOpValueStr(const T& v) { 28 #endif 29 return StreamValToStr(vp, f); 30 } 31 32 #undef SUPPORTS_BUILTIN_ADDRESSOF 33 34 // Overload for types that have no operator<< but do have .ToString() defined. 35 template <typename T> 36 -inline std::enable_if_t<!base::internal::SupportsOstreamOperator<const T&> && 37 - base::internal::SupportsToString<const T&>, 38 +inline std::enable_if_t< 39 + !base::internal::SupportsOstreamOperator<const T&>::value && 40 + base::internal::SupportsToString<const T&>::value, 41 char*> 42 CheckOpValueStr(const T& v) { 43 // .ToString() may not return a std::string, e.g. blink::WTF::String. 44 return CheckOpValueStr(v.ToString()); 45 } 46 47 // Provide an overload for functions and function pointers. Function pointers 48 // don't implicitly convert to void* but do implicitly convert to bool, so 49 @@ -114,18 +115,19 @@ inline std::enable_if_t< 50 char*> 51 CheckOpValueStr(const T& v) { 52 return CheckOpValueStr(reinterpret_cast<const void*>(v)); 53 } 54 55 // We need overloads for enums that don't support operator<<. 56 // (i.e. scoped enums where no operator<< overload was declared). 57 template <typename T> 58 -inline std::enable_if_t<!base::internal::SupportsOstreamOperator<const T&> && 59 - std::is_enum_v<T>, 60 +inline std::enable_if_t< 61 + !base::internal::SupportsOstreamOperator<const T&>::value && 62 + std::is_enum_v<T>, 63 char*> 64 CheckOpValueStr(const T& v) { 65 return CheckOpValueStr( 66 static_cast<typename std::underlying_type<T>::type>(v)); 67 } 68 69 // Takes ownership of `v1_str` and `v2_str`, destroying them with free(). For 70 // use with CheckOpValueStr() which allocates these strings using strdup(). 71 diff --git a/base/containers/contiguous_iterator.h b/base/containers/contiguous_iterator.h 72 --- a/base/containers/contiguous_iterator.h 73 +++ b/base/containers/contiguous_iterator.h 74 @@ -38,17 +38,19 @@ struct IsStringIterImpl 75 // 76 // Note: Requires indirection via `IsStringIterImpl` to avoid triggering a 77 // `static_assert(is_trivial_v<value_type>)` inside libc++'s std::basic_string. 78 template <typename T> 79 struct IsStringIter 80 : std::conjunction< 81 std::disjunction<std::is_same<iter_value_t<T>, char>, 82 std::is_same<iter_value_t<T>, wchar_t>, 83 +#if !defined(MOZ_SANDBOX) 84 std::is_same<iter_value_t<T>, char8_t>, 85 +#endif 86 std::is_same<iter_value_t<T>, char16_t>, 87 std::is_same<iter_value_t<T>, char32_t>>, 88 IsStringIterImpl<T>> {}; 89 90 // An iterator to std::array is contiguous. 91 // Reference: https://wg21.link/array.overview#1 92 template <typename T, typename ArrayT = std::array<iter_value_t<T>, 1>> 93 struct IsArrayIter 94 diff --git a/base/strings/to_string.h b/base/strings/to_string.h 95 --- a/base/strings/to_string.h 96 +++ b/base/strings/to_string.h 97 @@ -18,18 +18,21 @@ 98 99 namespace base { 100 101 template <typename... Ts> 102 std::string ToString(const Ts&... values); 103 104 namespace internal { 105 106 +template <typename T, typename = void> 107 +struct SupportsToString : std::false_type {}; 108 template <typename T> 109 -concept SupportsToString = requires(const T& t) { t.ToString(); }; 110 +struct SupportsToString<T, decltype(void(std::declval<T>().ToString()))> 111 + : std::true_type {}; 112 113 // I/O manipulators are function pointers, but should be sent directly to the 114 // `ostream` instead of being cast to `const void*` like other function 115 // pointers. 116 template <typename T, typename = void> 117 constexpr bool IsIomanip = false; 118 template <typename T> 119 constexpr bool 120 @@ -51,50 +54,50 @@ template <typename T, typename = void> 121 struct ToStringHelper { 122 static void Stringify(const T& v, std::ostringstream& ss) { 123 ss << "[" << sizeof(v) << "-byte object at 0x" << std::addressof(v) << "]"; 124 } 125 }; 126 127 // Most streamables. 128 template <typename T> 129 -struct ToStringHelper<T, 130 - std::enable_if_t<SupportsOstreamOperator<const T&> && 131 - !WillBeIncorrectlyStreamedAsBool<T>>> { 132 +struct ToStringHelper< 133 + T, std::enable_if_t<SupportsOstreamOperator<const T&>::value && 134 + !WillBeIncorrectlyStreamedAsBool<T>>> { 135 static void Stringify(const T& v, std::ostringstream& ss) { ss << v; } 136 }; 137 138 // Functions and function pointers. 139 template <typename T> 140 -struct ToStringHelper<T, 141 - std::enable_if_t<SupportsOstreamOperator<const T&> && 142 - WillBeIncorrectlyStreamedAsBool<T>>> { 143 +struct ToStringHelper< 144 + T, std::enable_if_t<SupportsOstreamOperator<const T&>::value && 145 + WillBeIncorrectlyStreamedAsBool<T>>> { 146 static void Stringify(const T& v, std::ostringstream& ss) { 147 ToStringHelper<const void*>::Stringify(reinterpret_cast<const void*>(v), 148 ss); 149 } 150 }; 151 152 // Non-streamables that have a `ToString` member. 153 template <typename T> 154 -struct ToStringHelper<T, 155 - std::enable_if_t<!SupportsOstreamOperator<const T&> && 156 - SupportsToString<const T&>>> { 157 +struct ToStringHelper< 158 + T, std::enable_if_t<!SupportsOstreamOperator<const T&>::value && 159 + SupportsToString<const T&>::value>> { 160 static void Stringify(const T& v, std::ostringstream& ss) { 161 // .ToString() may not return a std::string, e.g. blink::WTF::String. 162 ToStringHelper<decltype(v.ToString())>::Stringify(v.ToString(), ss); 163 } 164 }; 165 166 // Non-streamable enums (i.e. scoped enums where no `operator<<` overload was 167 // declared). 168 template <typename T> 169 struct ToStringHelper< 170 - T, 171 - std::enable_if_t<!SupportsOstreamOperator<const T&> && std::is_enum_v<T>>> { 172 + T, std::enable_if_t<!SupportsOstreamOperator<const T&>::value && 173 + std::is_enum_v<T>>> { 174 static void Stringify(const T& v, std::ostringstream& ss) { 175 using UT = typename std::underlying_type_t<T>; 176 ToStringHelper<UT>::Stringify(static_cast<UT>(v), ss); 177 } 178 }; 179 180 // Tuples. Will recursively apply `ToString()` to each value in the tuple. 181 template <typename... T> 182 diff --git a/base/types/strong_alias.h b/base/types/strong_alias.h 183 --- a/base/types/strong_alias.h 184 +++ b/base/types/strong_alias.h 185 @@ -149,17 +149,17 @@ class StrongAlias { 186 protected: 187 UnderlyingType value_; 188 }; 189 190 // Stream operator for convenience, streams the UnderlyingType. 191 template <typename TagType, 192 typename UnderlyingType, 193 typename = std::enable_if_t< 194 - internal::SupportsOstreamOperator<UnderlyingType>>> 195 + internal::SupportsOstreamOperator<UnderlyingType>::value>> 196 std::ostream& operator<<(std::ostream& stream, 197 const StrongAlias<TagType, UnderlyingType>& alias) { 198 return stream << alias.value(); 199 } 200 201 } // namespace base 202 203 #endif // BASE_TYPES_STRONG_ALIAS_H_ 204 diff --git a/sandbox/win/src/sandbox_policy_base.cc b/sandbox/win/src/sandbox_policy_base.cc 205 --- a/sandbox/win/src/sandbox_policy_base.cc 206 +++ b/sandbox/win/src/sandbox_policy_base.cc 207 @@ -805,12 +805,12 @@ absl::optional<base::span<const uint8_t> 208 return absl::nullopt; 209 } 210 211 void PolicyBase::AddDelegateData(base::span<const uint8_t> data) { 212 CHECK(data.size() > 0u); 213 // Can only set this once - as there is only one region sent to the child. 214 CHECK(!delegate_data_); 215 delegate_data_ = 216 - std::make_unique<std::vector<const uint8_t>>(data.begin(), data.end()); 217 + std::make_unique<const std::vector<uint8_t>>(data.begin(), data.end()); 218 } 219 220 } // namespace sandbox 221 diff --git a/sandbox/win/src/sandbox_policy_base.h b/sandbox/win/src/sandbox_policy_base.h 222 --- a/sandbox/win/src/sandbox_policy_base.h 223 +++ b/sandbox/win/src/sandbox_policy_base.h 224 @@ -248,17 +248,17 @@ class PolicyBase final : public TargetPo 225 226 // Returns nullopt if no data has been set, or a view into the data. 227 absl::optional<base::span<const uint8_t>> delegate_data_span(); 228 229 // The user-defined global policy settings. 230 HANDLE stdout_handle_; 231 HANDLE stderr_handle_; 232 // An opaque blob of data the delegate uses to prime any pre-sandbox hooks. 233 - std::unique_ptr<std::vector<const uint8_t>> delegate_data_; 234 + std::unique_ptr<const std::vector<uint8_t>> delegate_data_; 235 236 std::unique_ptr<Dispatcher> dispatcher_; 237 238 // Contains the list of handles being shared with the target process. 239 // This list contains handles other than the stderr/stdout handles which are 240 // shared with the target at times. 241 base::HandlesToInheritVector handles_to_share_; 242 Job job_;