Skip to content

Commit fd24d80

Browse files
committed
Upgrade fmt to 8.0.1
1 parent e102b26 commit fd24d80

File tree

8 files changed

+69
-67
lines changed

8 files changed

+69
-67
lines changed

engine/lib/fmt/color.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ void vformat_to(buffer<Char>& buf, const text_style& ts,
507507
auto background = detail::make_background_color<Char>(ts.get_background());
508508
buf.append(background.begin(), background.end());
509509
}
510-
detail::vformat_to(buf, format_str, args);
510+
detail::vformat_to(buf, format_str, args, {});
511511
if (has_style) detail::reset_color<Char>(buf);
512512
}
513513

engine/lib/fmt/core.h

+39-43
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
#include <type_traits>
1717

1818
// The fmt library version in the form major * 10000 + minor * 100 + patch.
19-
#define FMT_VERSION 80000
19+
#define FMT_VERSION 80001
2020

2121
#ifdef __clang__
2222
# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
2323
#else
2424
# define FMT_CLANG_VERSION 0
2525
#endif
2626

27-
#if defined(__GNUC__) && !defined(__clang__)
27+
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
2828
# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
2929
# define FMT_GCC_PRAGMA(arg) _Pragma(arg)
3030
#else
@@ -64,7 +64,8 @@
6464
# define FMT_HAS_FEATURE(x) 0
6565
#endif
6666

67-
#if defined(__has_include) && !defined(__INTELLISENSE__) && \
67+
#if defined(__has_include) && \
68+
(!defined(__INTELLISENSE__) || FMT_MSC_VER > 1900) && \
6869
(!FMT_ICC_VERSION || FMT_ICC_VERSION >= 1600)
6970
# define FMT_HAS_INCLUDE(x) __has_include(x)
7071
#else
@@ -228,12 +229,12 @@
228229
# define FMT_INLINE_NAMESPACE namespace
229230
# define FMT_END_NAMESPACE \
230231
} \
231-
using namespace v7; \
232+
using namespace v8; \
232233
}
233234
# endif
234235
# define FMT_BEGIN_NAMESPACE \
235236
namespace fmt { \
236-
FMT_INLINE_NAMESPACE v7 {
237+
FMT_INLINE_NAMESPACE v8 {
237238
#endif
238239

239240
#ifndef FMT_MODULE_EXPORT
@@ -316,9 +317,9 @@ FMT_BEGIN_NAMESPACE
316317
FMT_MODULE_EXPORT_BEGIN
317318

318319
// Implementations of enable_if_t and other metafunctions for older systems.
319-
template <bool B, class T = void>
320+
template <bool B, typename T = void>
320321
using enable_if_t = typename std::enable_if<B, T>::type;
321-
template <bool B, class T, class F>
322+
template <bool B, typename T, typename F>
322323
using conditional_t = typename std::conditional<B, T, F>::type;
323324
template <bool B> using bool_constant = std::integral_constant<bool, B>;
324325
template <typename T>
@@ -332,6 +333,11 @@ struct monostate {
332333
constexpr monostate() {}
333334
};
334335

336+
// Suppress "unused variable" warnings with the method described in
337+
// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
338+
// (void)var does not work on many Intel compilers.
339+
template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {}
340+
335341
// An enable_if helper to be used in template parameters which results in much
336342
// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
337343
// to workaround a bug in MSVC 2019 (see #1140 and #1186).
@@ -360,7 +366,8 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
360366
#ifndef FMT_ASSERT
361367
# ifdef NDEBUG
362368
// FMT_ASSERT is not empty to avoid -Werror=empty-body.
363-
# define FMT_ASSERT(condition, message) ((void)0)
369+
# define FMT_ASSERT(condition, message) \
370+
::fmt::ignore_unused((condition), (message))
364371
# else
365372
# define FMT_ASSERT(condition, message) \
366373
((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
@@ -525,39 +532,21 @@ using string_view = basic_string_view<char>;
525532
template <typename T> struct is_char : std::false_type {};
526533
template <> struct is_char<char> : std::true_type {};
527534

528-
/**
529-
\rst
530-
Returns a string view of `s`. In order to add custom string type support to
531-
{fmt} provide an overload of `to_string_view` for it in the same namespace as
532-
the type for the argument-dependent lookup to work.
533-
534-
**Example**::
535-
536-
namespace my_ns {
537-
inline string_view to_string_view(const my_string& s) {
538-
return {s.data(), s.length()};
539-
}
540-
}
541-
std::string message = fmt::format(my_string("The answer is {}"), 42);
542-
\endrst
543-
*/
535+
// Returns a string view of `s`.
544536
template <typename Char, FMT_ENABLE_IF(is_char<Char>::value)>
545537
FMT_INLINE auto to_string_view(const Char* s) -> basic_string_view<Char> {
546538
return s;
547539
}
548-
549540
template <typename Char, typename Traits, typename Alloc>
550541
inline auto to_string_view(const std::basic_string<Char, Traits, Alloc>& s)
551542
-> basic_string_view<Char> {
552543
return s;
553544
}
554-
555545
template <typename Char>
556546
constexpr auto to_string_view(basic_string_view<Char> s)
557547
-> basic_string_view<Char> {
558548
return s;
559549
}
560-
561550
template <typename Char,
562551
FMT_ENABLE_IF(!std::is_empty<detail::std_string_view<Char>>::value)>
563552
inline auto to_string_view(detail::std_string_view<Char> s)
@@ -581,7 +570,7 @@ constexpr auto to_string_view(const S& s)
581570
FMT_BEGIN_DETAIL_NAMESPACE
582571

583572
void to_string_view(...);
584-
using fmt::v7::to_string_view;
573+
using fmt::v8::to_string_view;
585574

586575
// Specifies whether S is a string type convertible to fmt::basic_string_view.
587576
// It should be a constexpr function but MSVC 2017 fails to compile it in
@@ -624,7 +613,7 @@ template <typename S> using char_t = typename detail::char_t_impl<S>::type;
624613
\rst
625614
Parsing context consisting of a format string range being parsed and an
626615
argument counter for automatic indexing.
627-
You can use the ```format_parse_context`` type alias for ``char`` instead.
616+
You can use the ``format_parse_context`` type alias for ``char`` instead.
628617
\endrst
629618
*/
630619
template <typename Char, typename ErrorHandler = detail::error_handler>
@@ -2420,7 +2409,7 @@ FMT_CONSTEXPR FMT_INLINE void parse_format_string(
24202409
if (pbegin == pend) return;
24212410
for (;;) {
24222411
const Char* p = nullptr;
2423-
if (!find<IS_CONSTEXPR>(pbegin, pend, '}', p))
2412+
if (!find<IS_CONSTEXPR>(pbegin, pend, Char('}'), p))
24242413
return handler_.on_text(pbegin, pend);
24252414
++p;
24262415
if (p == pend || *p != '}')
@@ -2435,7 +2424,7 @@ FMT_CONSTEXPR FMT_INLINE void parse_format_string(
24352424
// Doing two passes with memchr (one for '{' and another for '}') is up to
24362425
// 2.5x faster than the naive one-pass implementation on big format strings.
24372426
const Char* p = begin;
2438-
if (*begin != '{' && !find<IS_CONSTEXPR>(begin + 1, end, '{', p))
2427+
if (*begin != '{' && !find<IS_CONSTEXPR>(begin + 1, end, Char('{'), p))
24392428
return write(begin, end);
24402429
write(begin, p);
24412430
begin = parse_replacement_field(p, end, handler);
@@ -2588,8 +2577,8 @@ FMT_CONSTEXPR auto check_cstring_type_spec(Char spec, ErrorHandler&& eh = {})
25882577
return false;
25892578
}
25902579

2591-
template <typename Char, typename ErrorHandler>
2592-
FMT_CONSTEXPR void check_string_type_spec(Char spec, ErrorHandler&& eh) {
2580+
template <typename Char, typename ErrorHandler = error_handler>
2581+
FMT_CONSTEXPR void check_string_type_spec(Char spec, ErrorHandler&& eh = {}) {
25932582
if (spec != 0 && spec != 's') eh.on_error("invalid type specifier");
25942583
}
25952584

@@ -2656,21 +2645,28 @@ constexpr auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
26562645
if constexpr (detail::is_statically_named_arg<T>()) {
26572646
if (name == T::name) return N;
26582647
}
2659-
if constexpr (sizeof...(Args) > 0)
2648+
if constexpr (sizeof...(Args) > 0) {
26602649
return get_arg_index_by_name<N + 1, Args...>(name);
2661-
(void)name; // Workaround an MSVC bug about "unused" parameter.
2662-
return invalid_arg_index;
2650+
} else {
2651+
(void)name; // Workaround an MSVC bug about "unused" parameter.
2652+
return invalid_arg_index;
2653+
}
26632654
}
26642655
#endif
26652656

26662657
template <typename... Args, typename Char>
26672658
FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
26682659
#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
2669-
if constexpr (sizeof...(Args) > 0)
2660+
if constexpr (sizeof...(Args) > 0) {
26702661
return get_arg_index_by_name<0, Args...>(name);
2671-
#endif
2662+
} else {
2663+
(void)name;
2664+
return invalid_arg_index;
2665+
}
2666+
#else
26722667
(void)name;
26732668
return invalid_arg_index;
2669+
#endif
26742670
}
26752671

26762672
template <typename Char, typename ErrorHandler, typename... Args>
@@ -2731,14 +2727,14 @@ void check_format_string(S format_str) {
27312727
remove_cvref_t<Args>...>;
27322728
FMT_CONSTEXPR bool invalid_format =
27332729
(parse_format_string<true>(s, checker(s, {})), true);
2734-
(void)invalid_format;
2730+
ignore_unused(invalid_format);
27352731
}
27362732

27372733
template <typename Char>
27382734
void vformat_to(
27392735
buffer<Char>& buf, basic_string_view<Char> fmt,
27402736
basic_format_args<FMT_BUFFER_CONTEXT(type_identity_t<Char>)> args,
2741-
detail::locale_ref loc = {});
2737+
locale_ref loc = {});
27422738

27432739
FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
27442740
#ifndef _WIN32
@@ -2896,7 +2892,7 @@ template <typename OutputIt,
28962892
auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
28972893
using detail::get_buffer;
28982894
auto&& buf = get_buffer<char>(out);
2899-
detail::vformat_to(buf, string_view(fmt), args);
2895+
detail::vformat_to(buf, string_view(fmt), args, {});
29002896
return detail::get_iterator(buf);
29012897
}
29022898

@@ -2933,7 +2929,7 @@ auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args)
29332929
using buffer =
29342930
detail::iterator_buffer<OutputIt, char, detail::fixed_buffer_traits>;
29352931
auto buf = buffer(out, n);
2936-
detail::vformat_to(buf, fmt, args);
2932+
detail::vformat_to(buf, fmt, args, {});
29372933
return {buf.out(), buf.count()};
29382934
}
29392935

@@ -2955,7 +2951,7 @@ FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string<T...> fmt,
29552951
template <typename... T>
29562952
FMT_INLINE auto formatted_size(format_string<T...> fmt, T&&... args) -> size_t {
29572953
auto buf = detail::counting_buffer<>();
2958-
detail::vformat_to(buf, string_view(fmt), fmt::make_format_args(args...));
2954+
detail::vformat_to(buf, string_view(fmt), fmt::make_format_args(args...), {});
29592955
return buf.count();
29602956
}
29612957

engine/lib/fmt/format-inl.h

-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ class bigint {
563563
(*this)[bigit_index] = static_cast<bigit>(sum);
564564
sum >>= bits<bigit>::value;
565565
}
566-
--num_result_bigits;
567566
remove_leading_zeros();
568567
exp_ *= 2;
569568
}

engine/lib/fmt/format.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ template FMT_API char detail::decimal_point_impl(locale_ref);
4747

4848
template FMT_API void detail::buffer<char>::append(const char*, const char*);
4949

50+
// DEPRECATED!
51+
// There is no correspondent extern template in format.h because of
52+
// incompatibility between clang and gcc (#2377).
5053
template FMT_API void detail::vformat_to(
5154
detail::buffer<char>&, string_view,
5255
basic_format_args<FMT_BUFFER_CONTEXT(char)>, detail::locale_ref);

engine/lib/fmt/format.h

+22-19
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ FMT_CONSTEXPR inline size_t compute_width(string_view s) {
520520
1 +
521521
(error == 0 && cp >= 0x1100 &&
522522
(cp <= 0x115f || // Hangul Jamo init. consonants
523-
cp == 0x2329 || // LEFT-POINTING ANGLE BRACKET
524-
cp == 0x232a || // RIGHT-POINTING ANGLE BRACKET
525-
// CJK ... Yi except Unicode Character “〿”:
523+
cp == 0x2329 || // LEFT-POINTING ANGLE BRACKET
524+
cp == 0x232a || // RIGHT-POINTING ANGLE BRACKET
525+
// CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE:
526526
(cp >= 0x2e80 && cp <= 0xa4cf && cp != 0x303f) ||
527527
(cp >= 0xac00 && cp <= 0xd7a3) || // Hangul Syllables
528528
(cp >= 0xf900 && cp <= 0xfaff) || // CJK Compatibility Ideographs
@@ -603,7 +603,7 @@ enum { inline_buffer_size = 500 };
603603
A dynamically growing memory buffer for trivially copyable/constructible types
604604
with the first ``SIZE`` elements stored in the object itself.
605605
606-
You can use the ```memory_buffer`` type alias for ``char`` instead.
606+
You can use the ``memory_buffer`` type alias for ``char`` instead.
607607
608608
**Example**::
609609
@@ -859,7 +859,7 @@ template <typename T = void> struct basic_data {
859859
static const uint64_t log10_2_significand = 0x4d104d427de7fbcc;
860860

861861
// GCC generates slightly better code for pairs than chars.
862-
FMT_API static constexpr const char digits[][2] = {
862+
FMT_API static constexpr const char digits[100][2] = {
863863
{'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'},
864864
{'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, {'1', '0'}, {'1', '1'},
865865
{'1', '2'}, {'1', '3'}, {'1', '4'}, {'1', '5'}, {'1', '6'}, {'1', '7'},
@@ -879,11 +879,13 @@ template <typename T = void> struct basic_data {
879879
{'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}};
880880

881881
FMT_API static constexpr const char hex_digits[] = "0123456789abcdef";
882-
FMT_API static constexpr const char signs[] = {0, '-', '+', ' '};
882+
FMT_API static constexpr const char signs[4] = {0, '-', '+', ' '};
883883
FMT_API static constexpr const unsigned prefixes[4] = {0, 0, 0x1000000u | '+',
884884
0x1000000u | ' '};
885-
FMT_API static constexpr const char left_padding_shifts[] = {31, 31, 0, 1, 0};
886-
FMT_API static constexpr const char right_padding_shifts[] = {0, 31, 0, 1, 0};
885+
FMT_API static constexpr const char left_padding_shifts[5] = {31, 31, 0, 1,
886+
0};
887+
FMT_API static constexpr const char right_padding_shifts[5] = {0, 31, 0, 1,
888+
0};
887889
};
888890

889891
#ifdef FMT_SHARED
@@ -1023,7 +1025,7 @@ template <> inline auto decimal_point(locale_ref loc) -> wchar_t {
10231025

10241026
// Compares two characters for equality.
10251027
template <typename Char> auto equal2(const Char* lhs, const char* rhs) -> bool {
1026-
return lhs[0] == rhs[0] && lhs[1] == rhs[1];
1028+
return lhs[0] == Char(rhs[0]) && lhs[1] == Char(rhs[1]);
10271029
}
10281030
inline auto equal2(const char* lhs, const char* rhs) -> bool {
10291031
return memcmp(lhs, rhs, 2) == 0;
@@ -1567,6 +1569,7 @@ FMT_CONSTEXPR auto write(OutputIt out,
15671569
basic_string_view<type_identity_t<Char>> s,
15681570
const basic_format_specs<Char>& specs, locale_ref)
15691571
-> OutputIt {
1572+
check_string_type_spec(specs.type);
15701573
return write(out, s, specs);
15711574
}
15721575
template <typename Char, typename OutputIt>
@@ -2621,9 +2624,10 @@ auto to_string(const basic_memory_buffer<Char, SIZE>& buf)
26212624
FMT_BEGIN_DETAIL_NAMESPACE
26222625

26232626
template <typename Char>
2624-
void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
2625-
basic_format_args<buffer_context<type_identity_t<Char>>> args,
2626-
locale_ref loc) {
2627+
void vformat_to(
2628+
buffer<Char>& buf, basic_string_view<Char> fmt,
2629+
basic_format_args<FMT_BUFFER_CONTEXT(type_identity_t<Char>)> args,
2630+
locale_ref loc) {
26272631
// workaround for msvc bug regarding name-lookup in module
26282632
// link names into function scope
26292633
using detail::arg_formatter;
@@ -2703,10 +2707,6 @@ void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
27032707
}
27042708

27052709
#ifndef FMT_HEADER_ONLY
2706-
extern template void vformat_to(detail::buffer<char>&, string_view,
2707-
basic_format_args<format_context>,
2708-
detail::locale_ref);
2709-
27102710
extern template FMT_API auto thousands_sep_impl<char>(locale_ref)
27112711
-> thousands_sep_result<char>;
27122712
extern template FMT_API auto thousands_sep_impl<wchar_t>(locale_ref)
@@ -2730,6 +2730,8 @@ extern template auto snprintf_float<long double>(long double value,
27302730
#endif // FMT_HEADER_ONLY
27312731

27322732
FMT_END_DETAIL_NAMESPACE
2733+
2734+
#if FMT_USE_USER_DEFINED_LITERALS
27332735
inline namespace literals {
27342736
/**
27352737
\rst
@@ -2741,18 +2743,18 @@ inline namespace literals {
27412743
fmt::print("Elapsed time: {s:.2f} seconds", "s"_a=1.23);
27422744
\endrst
27432745
*/
2744-
#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
2746+
# if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
27452747
template <detail_exported::fixed_string Str>
27462748
constexpr auto operator""_a()
27472749
-> detail::udl_arg<remove_cvref_t<decltype(Str.data[0])>,
27482750
sizeof(Str.data) / sizeof(decltype(Str.data[0])), Str> {
27492751
return {};
27502752
}
2751-
#else
2753+
# else
27522754
constexpr auto operator"" _a(const char* s, size_t) -> detail::udl_arg<char> {
27532755
return {s};
27542756
}
2755-
#endif
2757+
# endif
27562758

27572759
/**
27582760
\rst
@@ -2769,6 +2771,7 @@ constexpr auto operator"" _format(const char* s, size_t n)
27692771
return {{s, n}};
27702772
}
27712773
} // namespace literals
2774+
#endif // FMT_USE_USER_DEFINED_LITERALS
27722775

27732776
template <typename Locale, FMT_ENABLE_IF(detail::is_locale<Locale>::value)>
27742777
inline auto vformat(const Locale& loc, string_view fmt, format_args args)

0 commit comments

Comments
 (0)