Skip to content

Commit 14afac9

Browse files
tomokinathiroyuki-komatsu
authored andcommitted
Unbreak build on windows.
Interestingly, (only) MSVC fails to compile a template function with an rvalue reference to an array, followed by a parameter with a default initializer of {} (e.g., void f(T (&&a)[N], T x = {})). See https://godbolt.org/z/cv3dhhro7 for details and a minimal, reproducible example. This patch uses a simple, equivalent alternative code that successfully compiles, found in the snippet above. PiperOrigin-RevId: 731333419
1 parent 64b5925 commit 14afac9

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/base/container/flat_internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace mozc::internal {
4646
// Sorts the given span in place.
4747
// C++17 backport of constexpr `std::sort` from C++20.
4848
template <class T, class Compare = std::less<>>
49-
constexpr void Sort(absl::Span<T> span, const Compare &cmp = {}) {
49+
constexpr void Sort(absl::Span<T> span, const Compare &cmp = Compare()) {
5050
// Since we're dealing with compile-time constants, expected to be small,
5151
// we use insertion sort. It's faster for small inputs, and easier to
5252
// implement :)
@@ -114,7 +114,7 @@ inline void DuplicateEntryFound() { LOG(FATAL) << "Duplicate entry found"; }
114114
// according to `cmp`.
115115
template <class T, class Compare = std::less<>>
116116
constexpr void SortAndVerifyUnique(absl::Span<T> span,
117-
const Compare &cmp = {}) {
117+
const Compare &cmp = Compare()) {
118118
Sort(span, cmp);
119119
for (int i = 0; i + i < span.size(); ++i) {
120120
if (!cmp(span[i], span[i + 1]) && !cmp(span[i + 1], span[i])) {

src/base/container/flat_map.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class FlatMap {
8888
// complex and explicitly declaring it would leak the number of entries, `N`.
8989
template <class K, class V, class CompareKey = std::less<>, size_t N>
9090
constexpr auto CreateFlatMap(Entry<K, V> (&&entries)[N],
91-
const CompareKey &cmp_key = {}) {
91+
const CompareKey &cmp_key = CompareKey()) {
9292
return FlatMap<K, V, CompareKey, N>(internal::ToArray(std::move(entries)),
9393
cmp_key);
9494
}

src/base/container/flat_multimap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class FlatMultimap {
9797
// complex and explicitly declaring it would leak the number of entries, `N`.
9898
template <class K, class V, class CompareKey = std::less<>, size_t N>
9999
constexpr auto CreateFlatMultimap(Entry<K, V> (&&entries)[N],
100-
const CompareKey &cmp_key = {}) {
100+
const CompareKey &cmp_key = CompareKey()) {
101101
return FlatMultimap<K, V, CompareKey, N>(
102102
internal::ToArray(std::move(entries)), cmp_key);
103103
}

src/base/container/flat_set.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class FlatSet {
7777
// Declare the variable as auto and use `CreateFlatSet`. The actual type is
7878
// complex and explicitly declaring it would leak the number of elements, `N`.
7979
template <class T, class Compare = std::less<>, size_t N>
80-
constexpr auto CreateFlatSet(T (&&elements)[N], const Compare &cmp = {}) {
80+
constexpr auto CreateFlatSet(T (&&elements)[N],
81+
const Compare &cmp = Compare()) {
8182
return FlatSet<T, Compare, N>(internal::ToArray(std::move(elements)), cmp);
8283
}
8384

0 commit comments

Comments
 (0)