From 11d21f100fdcf1c4aedea61dc754d06993360dfe Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 29 May 2023 13:01:36 +0300 Subject: [PATCH] win: Fix MSVC compile errors in registry.cc (fixes #3519) --- patch/patch.cfg | 6 +++ patch/patches/base_sandbox_3519.patch | 62 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 patch/patches/base_sandbox_3519.patch diff --git a/patch/patch.cfg b/patch/patch.cfg index 70068789c..970bb0d36 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -521,6 +521,12 @@ patches = [ # Avoid usage of PartitionAlloc assertions (PA_BASE_CHECK) in raw_ptr.h. 'name': 'base_sandbox_2743', }, + { + # Windows: Fix MSVC compile errors using base::MakeFixedFlatMapSorted + # in registry.cc when building cef_sandbox. + # https://github.com/chromiumembedded/cef/issues/3519 + 'name': 'base_sandbox_3519', + }, { # Add RenderWidgetHostImpl::SetCompositorForFlingScheduler to fix fling # scrolling in OSR mode. diff --git a/patch/patches/base_sandbox_3519.patch b/patch/patches/base_sandbox_3519.patch new file mode 100644 index 000000000..aebef05fa --- /dev/null +++ b/patch/patches/base_sandbox_3519.patch @@ -0,0 +1,62 @@ +diff --git base/ranges/ranges.h base/ranges/ranges.h +index 641bbaf2c7576..afdd641e38452 100644 +--- base/ranges/ranges.h ++++ base/ranges/ranges.h +@@ -30,12 +30,14 @@ constexpr T* begin(std::array& array, priority_tag<2> tag) { + return const_cast(begin(const_cast&>(array), tag)); + } + ++#if !defined(CEF_EXCLUDE_PROBLEMATIC_CONST_ARRAY_OVERLOADS) + // Overload for const std::array. Required since std::array::begin is not + // constexpr prior to C++17. + template + constexpr const T* begin(const std::array& array, priority_tag<2>) { + return N != 0 ? &array[0] : nullptr; + } ++#endif + + // Generic container overload. + template +@@ -65,12 +67,14 @@ constexpr T* end(std::array& array, priority_tag<2> tag) { + return const_cast(end(const_cast&>(array), tag)); + } + ++#if !defined(CEF_EXCLUDE_PROBLEMATIC_CONST_ARRAY_OVERLOADS) + // Overload for const std::array. Required since std::array::end is not + // constexpr prior to C++17. + template + constexpr const T* end(const std::array& array, priority_tag<2>) { + return N != 0 ? (&array[0]) + N : nullptr; + } ++#endif + + // Generic container overload. + template +diff --git base/win/registry.cc base/win/registry.cc +index 473f5fdc861ce..eb85a31611560 100644 +--- base/win/registry.cc ++++ base/win/registry.cc +@@ -13,6 +13,14 @@ + #include + #include + ++#include "cef/libcef/features/features.h" ++ ++#if BUILDFLAG(IS_CEF_SANDBOX_BUILD) ++// Avoid overloads for const std::array in base/ranges/ranges.h that don't ++// compile with MSVC. See issue #3519. ++#define CEF_EXCLUDE_PROBLEMATIC_CONST_ARRAY_OVERLOADS 1 ++#endif ++ + #include "base/check_op.h" + #include "base/containers/fixed_flat_map.h" + #include "base/functional/callback.h" +@@ -314,7 +322,7 @@ class ExportDerived { + {"RegSetValueExW", reinterpret_cast(®_set_value_ex_)}, + }); + +- auto* entry = kMap.find(name); ++ auto entry = kMap.find(name); + if (entry == kMap.end()) { + return true; + }