Sophie

Sophie

distrib > Mageia > 9 > aarch64 > media > tainted-updates-src > by-pkgid > 53e82d52de6621aa4524e6ebb5d8f226 > files > 35

chromium-browser-stable-124.0.6367.60-1.mga9.tainted.src.rpm

diff --git a/base/types/to_address.h.new b/base/types/to_address.h.new
new file mode 100644
index 0000000..ac71b01
--- /dev/null
+++ b/base/types/to_address.h
@@ -0,0 +1,40 @@
+// Copyright 2024 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TYPES_TO_ADDRESS_H_
+#define BASE_TYPES_TO_ADDRESS_H_
+
+#include <memory>
+#include <type_traits>
+
+// SFINAE-compatible wrapper for `std::to_address()`.
+//
+// The standard does not require `std::to_address()` to be SFINAE-compatible
+// when code attempts instantiation with non-pointer-like types, and libstdc++'s
+// implementation hard errors. For the sake of templated code that wants simple,
+// unified handling, Chromium instead uses this wrapper, which provides that
+// guarantee. This allows code to use "`to_address()` would be valid here" as a
+// constraint to detect pointer-like types.
+namespace base {
+
+// Note that calling `std::to_address()` with a function pointer renders the
+// program ill-formed.
+template <typename T>
+  requires(!std::is_function_v<T>)
+constexpr T* to_address(T* p) noexcept {
+  return p;
+}
+
+// These constraints cover the cases where `std::to_address()`'s fancy pointer
+// overload is well-specified.
+template <typename P>
+  requires requires(const P& p) { std::pointer_traits<P>::to_address(p); } ||
+           requires(const P& p) { p.operator->(); }
+constexpr auto to_address(const P& p) noexcept {
+  return std::to_address(p);
+}
+
+}  // namespace base
+
+#endif  // BASE_TYPES_TO_ADDRESS_H_
diff --git a/mojo/public/cpp/bindings/type_converter.h b/mojo/public/cpp/bindings/type_converter.h.new
index 2eddbb0..317245f 100644
--- a/mojo/public/cpp/bindings/type_converter.h
+++ b/mojo/public/cpp/bindings/type_converter.h
@@ -11,6 +11,8 @@
 #include <memory>
 #include <type_traits>
 
+#include "base/types/to_address.h"
+
 namespace mojo {
 
 // NOTE: When possible, please consider using StructTraits / UnionTraits /
@@ -99,16 +99,16 @@
 
 template <typename T, typename U>
   requires requires(const U& obj) {
-    not std::is_pointer_v<U>;
-    { mojo::ConvertTo<T>(std::to_address(obj)) } -> std::same_as<T>;
+    !std::is_pointer_v<U>;
+    { mojo::ConvertTo<T>(base::to_address(obj)) } -> std::same_as<T>;
   }
 inline T ConvertTo(const U& obj) {
-  return mojo::ConvertTo<T>(std::to_address(obj));
+  return mojo::ConvertTo<T>(base::to_address(obj));
 }
 
 template <typename T, typename U>
   requires requires(const U& obj) {
-    not std::is_pointer_v<U>;
+    !std::is_pointer_v<U>;
     TypeConverter<T, U>::Convert(obj);
   }
 inline T ConvertTo(const U& obj) {