From 7058e49247ed811bb39a9cce635ad62209319473 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 26 Feb 2025 19:01:09 +0000 Subject: [PATCH] Update fmtlib. --- vendor/README.md | 2 +- vendor/fmt/base.h | 46 ++++++++++++++---------- vendor/fmt/chrono.h | 4 +-- vendor/fmt/compile.h | 32 ++++++----------- vendor/fmt/format-inl.h | 6 ++-- vendor/fmt/format.h | 78 +++++++++++++++++++++++++++-------------- vendor/fmt/ostream.h | 2 +- vendor/fmt/ranges.h | 4 ++- vendor/fmt/std.h | 9 +++-- vendor/fmt/xchar.h | 27 ++++++++------ 10 files changed, 119 insertions(+), 91 deletions(-) diff --git a/vendor/README.md b/vendor/README.md index 4a5d21dff..3363135a5 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -18,7 +18,7 @@ This directory contains vendored dependencies that are shipped with InspIRCd to **License** — MIT License -**Version** — 11.1.1 +**Version** — 11.1.4 **Website** — [https://github.com/fmtlib/fmt/](https://github.com/fmtlib/fmt/) diff --git a/vendor/fmt/base.h b/vendor/fmt/base.h index 00c51423e..b886317d6 100644 --- a/vendor/fmt/base.h +++ b/vendor/fmt/base.h @@ -21,7 +21,7 @@ #endif // The fmt library version in the form major * 10000 + minor * 100 + patch. -#define FMT_VERSION 110101 +#define FMT_VERSION 110104 // Detect compiler versions. #if defined(__clang__) && !defined(__ibmxl__) @@ -96,9 +96,9 @@ // Detect C++14 relaxed constexpr. #ifdef FMT_USE_CONSTEXPR // Use the provided definition. -#elif FMT_GCC_VERSION >= 600 && FMT_CPLUSPLUS >= 201402L -// GCC only allows throw in constexpr since version 6: -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67371. +#elif FMT_GCC_VERSION >= 702 && FMT_CPLUSPLUS >= 201402L +// GCC only allows constexpr member functions in non-literal types since 7.2: +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66297. # define FMT_USE_CONSTEXPR 1 #elif FMT_ICC_VERSION # define FMT_USE_CONSTEXPR 0 // https://github.com/fmtlib/fmt/issues/1628 @@ -294,12 +294,12 @@ #endif #define FMT_APPLY_VARIADIC(expr) \ - using ignore = int[]; \ - (void)ignore { 0, (expr, 0)... } + using unused = int[]; \ + (void)unused { 0, (expr, 0)... } // Enable minimal optimizations for more compact code in debug mode. FMT_PRAGMA_GCC(push_options) -#if !defined(__OPTIMIZE__) && !defined(__CUDACC__) +#if !defined(__OPTIMIZE__) && !defined(__CUDACC__) && !defined(FMT_MODULE) FMT_PRAGMA_GCC(optimize("Og")) #endif FMT_PRAGMA_CLANG(diagnostic push) @@ -537,7 +537,7 @@ template class basic_string_view { FMT_ALWAYS_INLINE #endif FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) { -#if FMT_HAS_BUILTIN(__buitin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION +#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION if (std::is_same::value) { size_ = __builtin_strlen(detail::narrow(s)); return; @@ -739,13 +739,15 @@ class basic_specs { max_fill_size = 4 }; - size_t data_ = 1 << fill_size_shift; + unsigned data_ = 1 << fill_size_shift; + static_assert(sizeof(basic_specs::data_) * CHAR_BIT >= 18, ""); // Character (code unit) type is erased to prevent template bloat. char fill_data_[max_fill_size] = {' '}; FMT_CONSTEXPR void set_fill_size(size_t size) { - data_ = (data_ & ~fill_size_mask) | (size << fill_size_shift); + data_ = (data_ & ~fill_size_mask) | + (static_cast(size) << fill_size_shift); } public: @@ -842,6 +844,12 @@ class basic_specs { for (size_t i = 0; i < size; ++i) fill_data_[i & 3] = static_cast(s[i]); } + + FMT_CONSTEXPR void copy_fill_from(const basic_specs& specs) { + set_fill_size(specs.fill_size()); + for (size_t i = 0; i < max_fill_size; ++i) + fill_data_[i] = specs.fill_data_[i]; + } }; // Format specifiers for built-in and string types. @@ -1113,7 +1121,7 @@ using use_formatter = bool_constant<(std::is_class::value || std::is_enum::value || std::is_union::value || std::is_array::value) && !has_to_string_view::value && !is_named_arg::value && - !use_format_as::value && !use_format_as_member::value>; + !use_format_as::value && !use_format_as_member::value>; template > auto has_formatter_impl(T* p, buffered_context* ctx = nullptr) @@ -2255,28 +2263,27 @@ template <> struct is_output_iterator : std::true_type {}; template struct is_output_iterator< It, T, - void_t&>()++ = std::declval())>> - : std::true_type {}; + enable_if_t&>()++), + T>::value>> : std::true_type {}; #ifndef FMT_USE_LOCALE # define FMT_USE_LOCALE (FMT_OPTIMIZE_SIZE <= 1) #endif // A type-erased reference to an std::locale to avoid a heavy include. -struct locale_ref { +class locale_ref { #if FMT_USE_LOCALE private: const void* locale_; // A type-erased pointer to std::locale. public: constexpr locale_ref() : locale_(nullptr) {} - - template - locale_ref(const Locale& loc); + template locale_ref(const Locale& loc); inline explicit operator bool() const noexcept { return locale_ != nullptr; } #endif // FMT_USE_LOCALE + public: template auto get() const -> Locale; }; @@ -2650,6 +2657,7 @@ class context { FMT_CONSTEXPR auto arg_id(string_view name) const -> int { return args_.get_id(name); } + auto args() const -> const format_args& { return args_; } // Returns an iterator to the beginning of the output range. FMT_CONSTEXPR auto out() const -> iterator { return out_; } @@ -2722,9 +2730,9 @@ template struct fstring { std::is_same::value)> FMT_ALWAYS_INLINE fstring(const S&) : str(S()) { FMT_CONSTEXPR auto sv = string_view(S()); - FMT_CONSTEXPR int ignore = + FMT_CONSTEXPR int unused = (parse_format_string(sv, checker(sv, arg_pack())), 0); - detail::ignore_unused(ignore); + detail::ignore_unused(unused); } fstring(runtime_format_string<> fmt) : str(fmt.str) {} diff --git a/vendor/fmt/chrono.h b/vendor/fmt/chrono.h index abf3671e5..50c777c84 100644 --- a/vendor/fmt/chrono.h +++ b/vendor/fmt/chrono.h @@ -261,7 +261,7 @@ namespace detail { using utc_clock = std::chrono::utc_clock; #else struct utc_clock { - void to_sys(); + template void to_sys(T); }; #endif @@ -364,7 +364,7 @@ void write_codecvt(codecvt_result& out, string_view in, template auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale& loc) -> OutputIt { - if (detail::use_utf8 && loc != get_classic_locale()) { + if (const_check(detail::use_utf8) && loc != get_classic_locale()) { // char16_t and char32_t codecvts are broken in MSVC (linkage errors) and // gcc-4. #if FMT_MSC_VERSION != 0 || \ diff --git a/vendor/fmt/compile.h b/vendor/fmt/compile.h index 68b451c71..08d9427ff 100644 --- a/vendor/fmt/compile.h +++ b/vendor/fmt/compile.h @@ -19,11 +19,11 @@ FMT_BEGIN_NAMESPACE // A compile-time string which is compiled into fast formatting code. FMT_EXPORT class compiled_string {}; -namespace detail { - template struct is_compiled_string : std::is_base_of {}; +namespace detail { + /** * Converts a string literal `s` into a format string that will be parsed at * compile time and converted into efficient formatting code. Requires C++17 @@ -41,16 +41,6 @@ struct is_compiled_string : std::is_base_of {}; # define FMT_COMPILE(s) FMT_STRING(s) #endif -#if FMT_USE_NONTYPE_TEMPLATE_ARGS -template Str> -struct udl_compiled_string : compiled_string { - using char_type = Char; - constexpr explicit operator basic_string_view() const { - return {Str.data, N - 1}; - } -}; -#endif - template auto first(const T& value, const Tail&...) -> const T& { return value; @@ -425,7 +415,7 @@ constexpr auto compile_format_string(S fmt) { } template ::value)> + FMT_ENABLE_IF(is_compiled_string::value)> constexpr auto compile(S fmt) { constexpr auto str = basic_string_view(fmt); if constexpr (str.size() == 0) { @@ -461,7 +451,7 @@ constexpr FMT_INLINE OutputIt format_to(OutputIt out, const CompiledFormat& cf, } template ::value)> + FMT_ENABLE_IF(is_compiled_string::value)> FMT_INLINE std::basic_string format(const S&, Args&&... args) { if constexpr (std::is_same::value) { @@ -488,7 +478,7 @@ FMT_INLINE std::basic_string format(const S&, } template ::value)> + FMT_ENABLE_IF(is_compiled_string::value)> FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) { constexpr auto compiled = detail::compile(S()); if constexpr (std::is_same, @@ -503,7 +493,7 @@ FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) { #endif template ::value)> + FMT_ENABLE_IF(is_compiled_string::value)> auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args) -> format_to_n_result { using traits = detail::fixed_buffer_traits; @@ -513,7 +503,7 @@ auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args) } template ::value)> + FMT_ENABLE_IF(is_compiled_string::value)> FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args) -> size_t { auto buf = detail::counting_buffer<>(); @@ -522,7 +512,7 @@ FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args) } template ::value)> + FMT_ENABLE_IF(is_compiled_string::value)> void print(std::FILE* f, const S& fmt, const Args&... args) { auto buf = memory_buffer(); fmt::format_to(appender(buf), fmt, args...); @@ -530,7 +520,7 @@ void print(std::FILE* f, const S& fmt, const Args&... args) { } template ::value)> + FMT_ENABLE_IF(is_compiled_string::value)> void print(const S& fmt, const Args&... args) { print(stdout, fmt, args...); } @@ -538,9 +528,7 @@ void print(const S& fmt, const Args&... args) { #if FMT_USE_NONTYPE_TEMPLATE_ARGS inline namespace literals { template constexpr auto operator""_cf() { - using char_t = remove_cvref_t; - return detail::udl_compiled_string(); + return FMT_COMPILE(Str.data); } } // namespace literals #endif diff --git a/vendor/fmt/format-inl.h b/vendor/fmt/format-inl.h index 38308bf2a..a5b79dbe4 100644 --- a/vendor/fmt/format-inl.h +++ b/vendor/fmt/format-inl.h @@ -84,7 +84,7 @@ using std::locale; using std::numpunct; using std::use_facet; -template > +template locale_ref::locale_ref(const Locale& loc) : locale_(&loc) { static_assert(std::is_same::value, ""); } @@ -134,7 +134,9 @@ FMT_FUNC auto write_loc(appender out, loc_value value, FMT_FUNC void report_error(const char* message) { #if FMT_USE_EXCEPTIONS - throw format_error(message); + // Use FMT_THROW instead of throw to avoid bogus unreachable code warnings + // from MSVC. + FMT_THROW(format_error(message)); #else fputs(message, stderr); abort(); diff --git a/vendor/fmt/format.h b/vendor/fmt/format.h index d1b83d186..287e71631 100644 --- a/vendor/fmt/format.h +++ b/vendor/fmt/format.h @@ -227,7 +227,9 @@ FMT_CONSTEXPR inline void abort_fuzzing_if(bool condition) { #if defined(FMT_USE_STRING_VIEW) template using std_string_view = std::basic_string_view; #else -template struct std_string_view {}; +template struct std_string_view { + operator basic_string_view() const; +}; #endif template struct string_literal { @@ -1203,7 +1205,7 @@ FMT_CONSTEXPR FMT_INLINE auto format_decimal(Char* out, UInt value, } template ::value)> + FMT_ENABLE_IF(!std::is_pointer>::value)> FMT_CONSTEXPR auto format_decimal(OutputIt out, UInt value, int num_digits) -> OutputIt { if (auto ptr = to_pointer(out, to_unsigned(num_digits))) { @@ -1839,7 +1841,9 @@ template class digit_grouping { } public: - explicit digit_grouping(locale_ref loc, bool localized = true) { + template ::value)> + explicit digit_grouping(Locale loc, bool localized = true) { if (!localized) return; auto sep = thousands_sep(loc); grouping_ = sep.grouping; @@ -2328,7 +2332,7 @@ template > FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f, const format_specs& specs, sign s, - locale_ref loc) -> OutputIt { + int exp_upper, locale_ref loc) -> OutputIt { auto significand = f.significand; int significand_size = get_significand_size(f); const Char zero = static_cast('0'); @@ -2344,7 +2348,7 @@ FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f, if (specs.type() == presentation_type::fixed) return false; // Use the fixed notation if the exponent is in [exp_lower, exp_upper), // e.g. 0.0001 instead of 1e-04. Otherwise use the exponent notation. - const int exp_lower = -4, exp_upper = 16; + const int exp_lower = -4; return output_exp < exp_lower || output_exp >= (specs.precision > 0 ? specs.precision : exp_upper); }; @@ -2447,12 +2451,13 @@ template class fallback_digit_grouping { template FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f, const format_specs& specs, sign s, - locale_ref loc) -> OutputIt { + int exp_upper, locale_ref loc) -> OutputIt { if (is_constant_evaluated()) { return do_write_float>(out, f, specs, s, loc); + fallback_digit_grouping>(out, f, specs, s, + exp_upper, loc); } else { - return do_write_float(out, f, specs, s, loc); + return do_write_float(out, f, specs, s, exp_upper, loc); } } @@ -3284,6 +3289,14 @@ FMT_CONSTEXPR20 auto format_float(Float value, int precision, return exp; } +// Numbers with exponents greater or equal to the returned value will use +// the exponential notation. +template constexpr auto exp_upper() -> int { + return std::numeric_limits::digits10 != 0 + ? min_of(16, std::numeric_limits::digits10 + 1) + : 16; +} + template FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs, locale_ref loc) -> OutputIt { @@ -3299,6 +3312,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs, if (specs.width != 0) --specs.width; } + constexpr int exp_upper = detail::exp_upper(); int precision = specs.precision; if (precision < 0) { if (specs.type() != presentation_type::none) { @@ -3307,7 +3321,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs, // Use Dragonbox for the shortest format. using floaty = conditional_t= sizeof(double), double, float>; auto dec = dragonbox::to_decimal(static_cast(value)); - return write_float(out, dec, specs, s, loc); + return write_float(out, dec, specs, s, exp_upper, loc); } } @@ -3335,7 +3349,7 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, format_specs specs, specs.precision = precision; auto f = big_decimal_fp{buffer.data(), static_cast(buffer.size()), exp}; - return write_float(out, f, specs, s, loc); + return write_float(out, f, specs, s, exp_upper, loc); } template OutputIt { return write_nonfinite(out, std::isnan(value), specs, s); auto dec = dragonbox::to_decimal(static_cast(value)); - return write_float(out, dec, specs, s, {}); + return write_float(out, dec, specs, s, exp_upper(), {}); } template ::format( return write(ctx.out(), val, specs, ctx.locale()); } +// DEPRECATED! https://github.com/fmtlib/fmt/issues/4292. +template +struct is_locale : std::false_type {}; +template +struct is_locale> : std::true_type {}; + // DEPRECATED! template struct vformat_args { using type = basic_format_args>; @@ -3960,8 +3980,7 @@ template struct nested_formatter { write(basic_appender(buf)); auto specs = format_specs(); specs.width = width_; - specs.set_fill( - basic_string_view(specs_.fill(), specs_.fill_size())); + specs.copy_fill_from(specs_); specs.set_align(specs_.align()); return detail::write( ctx.out(), basic_string_view(buf.data(), buf.size()), specs); @@ -4121,41 +4140,46 @@ FMT_API void format_system_error(detail::buffer& out, int error_code, // Can be used to report errors from destructors. FMT_API void report_system_error(int error_code, const char* message) noexcept; -inline auto vformat(detail::locale_ref loc, string_view fmt, format_args args) +template ::value)> +inline auto vformat(const Locale& loc, string_view fmt, format_args args) -> std::string { auto buf = memory_buffer(); - detail::vformat_to(buf, fmt, args, loc); + detail::vformat_to(buf, fmt, args, detail::locale_ref(loc)); return {buf.data(), buf.size()}; } -template -FMT_INLINE auto format(detail::locale_ref loc, format_string fmt, - T&&... args) -> std::string { +template ::value)> +FMT_INLINE auto format(const Locale& loc, format_string fmt, T&&... args) + -> std::string { return vformat(loc, fmt.str, vargs{{args...}}); } -template ::value)> -auto vformat_to(OutputIt out, detail::locale_ref loc, string_view fmt, +auto vformat_to(OutputIt out, const Locale& loc, string_view fmt, format_args args) -> OutputIt { auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, fmt, args, loc); + detail::vformat_to(buf, fmt, args, detail::locale_ref(loc)); return detail::get_iterator(buf, out); } -template ::value)> -FMT_INLINE auto format_to(OutputIt out, detail::locale_ref loc, +template ::value&& + detail::is_locale::value)> +FMT_INLINE auto format_to(OutputIt out, const Locale& loc, format_string fmt, T&&... args) -> OutputIt { return fmt::vformat_to(out, loc, fmt.str, vargs{{args...}}); } -template -FMT_NODISCARD FMT_INLINE auto formatted_size(detail::locale_ref loc, +template ::value)> +FMT_NODISCARD FMT_INLINE auto formatted_size(const Locale& loc, format_string fmt, T&&... args) -> size_t { auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, fmt.str, vargs{{args...}}, loc); + detail::vformat_to(buf, fmt.str, vargs{{args...}}, + detail::locale_ref(loc)); return buf.count(); } diff --git a/vendor/fmt/ostream.h b/vendor/fmt/ostream.h index 5d893c921..71fd6c887 100644 --- a/vendor/fmt/ostream.h +++ b/vendor/fmt/ostream.h @@ -150,7 +150,7 @@ inline void vprint(std::ostream& os, string_view fmt, format_args args) { FMT_EXPORT template void print(std::ostream& os, format_string fmt, T&&... args) { fmt::vargs vargs = {{args...}}; - if (detail::use_utf8) return vprint(os, fmt.str, vargs); + if (detail::const_check(detail::use_utf8)) return vprint(os, fmt.str, vargs); auto buffer = memory_buffer(); detail::vformat_to(buffer, fmt.str, vargs); detail::write_buffer(os, buffer); diff --git a/vendor/fmt/ranges.h b/vendor/fmt/ranges.h index 118d24fe8..77d645f8e 100644 --- a/vendor/fmt/ranges.h +++ b/vendor/fmt/ranges.h @@ -527,7 +527,9 @@ struct formatter< template struct formatter< R, Char, - enable_if_t::value == range_format::map>> { + enable_if_t::value == range_format::map>, + detail::is_formattable_delayed>::value>> { private: using map_type = detail::maybe_const_range; using element_type = detail::uncvref_type; diff --git a/vendor/fmt/std.h b/vendor/fmt/std.h index b00e40225..54eb2c2a7 100644 --- a/vendor/fmt/std.h +++ b/vendor/fmt/std.h @@ -184,7 +184,8 @@ FMT_END_NAMESPACE FMT_BEGIN_NAMESPACE FMT_EXPORT template -struct formatter, Char> : nested_formatter { +struct formatter, Char> + : nested_formatter, Char> { private: // Functor because C++11 doesn't support generic lambdas. struct writer { @@ -204,7 +205,7 @@ struct formatter, Char> : nested_formatter { template auto format(const std::bitset& bs, FormatContext& ctx) const -> decltype(ctx.out()) { - return write_padded(ctx, writer{bs}); + return this->write_padded(ctx, writer{bs}); } }; @@ -695,9 +696,7 @@ template struct formatter, Char> { auto outer_specs = format_specs(); outer_specs.width = specs.width; - auto fill = specs.template fill(); - if (fill) - outer_specs.set_fill(basic_string_view(fill, specs.fill_size())); + outer_specs.copy_fill_from(specs); outer_specs.set_align(specs.align()); specs.width = 0; diff --git a/vendor/fmt/xchar.h b/vendor/fmt/xchar.h index 4cbda5421..9f7f889d6 100644 --- a/vendor/fmt/xchar.h +++ b/vendor/fmt/xchar.h @@ -191,9 +191,11 @@ auto format(const S& fmt, T&&... args) -> std::basic_string { fmt::make_format_args>(args...)); } -template , - FMT_ENABLE_IF(detail::is_exotic_char::value)> -inline auto vformat(detail::locale_ref loc, const S& fmt, +template , + FMT_ENABLE_IF(detail::is_locale::value&& + detail::is_exotic_char::value)> +inline auto vformat(const Locale& loc, const S& fmt, typename detail::vformat_args::type args) -> std::basic_string { auto buf = basic_memory_buffer(); @@ -202,10 +204,11 @@ inline auto vformat(detail::locale_ref loc, const S& fmt, return {buf.data(), buf.size()}; } -template , - FMT_ENABLE_IF(detail::is_exotic_char::value)> -inline auto format(detail::locale_ref loc, const S& fmt, T&&... args) + FMT_ENABLE_IF(detail::is_locale::value&& + detail::is_exotic_char::value)> +inline auto format(const Locale& loc, const S& fmt, T&&... args) -> std::basic_string { return vformat(loc, detail::to_string_view(fmt), fmt::make_format_args>(args...)); @@ -232,11 +235,12 @@ inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt { fmt::make_format_args>(args...)); } -template , FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> -inline auto vformat_to(OutputIt out, detail::locale_ref loc, const S& fmt, + detail::is_locale::value&& + detail::is_exotic_char::value)> +inline auto vformat_to(OutputIt out, const Locale& loc, const S& fmt, typename detail::vformat_args::type args) -> OutputIt { auto&& buf = detail::get_buffer(out); @@ -244,11 +248,12 @@ inline auto vformat_to(OutputIt out, detail::locale_ref loc, const S& fmt, return detail::get_iterator(buf, out); } -template , bool enable = detail::is_output_iterator::value && + detail::is_locale::value && detail::is_exotic_char::value> -inline auto format_to(OutputIt out, detail::locale_ref loc, const S& fmt, +inline auto format_to(OutputIt out, const Locale& loc, const S& fmt, T&&... args) -> typename std::enable_if::type { return vformat_to(out, loc, detail::to_string_view(fmt),