From 32ed9c5f0b5a602d40c84cf675fe3cd54377aaa9 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 7 Jul 2024 06:40:15 -0700 Subject: [PATCH] [upstream_utils] Upgrade to fmt 11.0.1 (#6804) --- upstream_utils/update_fmt.py | 2 +- .../thirdparty/fmtlib/include/fmt/base.h | 6 +- .../thirdparty/fmtlib/include/fmt/printf.h | 4 +- .../thirdparty/fmtlib/include/fmt/std.h | 76 ++++++++++++++----- 4 files changed, 61 insertions(+), 27 deletions(-) diff --git a/upstream_utils/update_fmt.py b/upstream_utils/update_fmt.py index 4bdcd7b385..94aef193f7 100755 --- a/upstream_utils/update_fmt.py +++ b/upstream_utils/update_fmt.py @@ -13,7 +13,7 @@ from upstream_utils import ( def main(): - upstream_root = clone_repo("https://github.com/fmtlib/fmt", "11.0.0") + upstream_root = clone_repo("https://github.com/fmtlib/fmt", "11.0.1") wpilib_root = get_repo_root() wpiutil = os.path.join(wpilib_root, "wpiutil") diff --git a/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/base.h b/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/base.h index 976402a42b..f440cffd20 100644 --- a/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/base.h +++ b/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/base.h @@ -23,7 +23,7 @@ #endif // The fmt library version in the form major * 10000 + minor * 100 + patch. -#define FMT_VERSION 110000 +#define FMT_VERSION 110001 // Detect compiler versions. #if defined(__clang__) && !defined(__ibmxl__) @@ -262,7 +262,7 @@ #ifndef FMT_BEGIN_NAMESPACE # define FMT_BEGIN_NAMESPACE \ namespace fmt { \ - inline namespace v10 { + inline namespace v11 { # define FMT_END_NAMESPACE \ } \ } @@ -1760,7 +1760,7 @@ template class basic_format_arg { * `vis(value)` will be called with the value of type `double`. */ template - FMT_CONSTEXPR auto visit(Visitor&& vis) -> decltype(vis(0)) { + FMT_CONSTEXPR auto visit(Visitor&& vis) const -> decltype(vis(0)) { switch (type_) { case detail::type::none_type: break; diff --git a/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/printf.h b/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/printf.h index ee4b06fd5e..072cc6b309 100644 --- a/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/printf.h +++ b/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/printf.h @@ -569,8 +569,8 @@ using wprintf_args = basic_format_args; /// arguments and can be implicitly converted to `printf_args`. template inline auto make_printf_args(T&... args) - -> decltype(make_format_args>(args...)) { - return make_format_args>(args...); + -> decltype(fmt::make_format_args>(args...)) { + return fmt::make_format_args>(args...); } template struct vprintf_args { diff --git a/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/std.h b/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/std.h index 01a61cee61..fb43940bc0 100644 --- a/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/std.h +++ b/wpiutil/src/main/native/thirdparty/fmtlib/include/fmt/std.h @@ -291,7 +291,7 @@ struct formatter, Char, if (value.has_value()) { out = detail::write(out, "expected("); - out = detail::write_escaped_alternative(out, value.value()); + out = detail::write_escaped_alternative(out, *value); } else { out = detail::write(out, "unexpected("); out = detail::write_escaped_alternative(out, value.error()); @@ -631,33 +631,67 @@ struct formatter : formatter { #endif // __cpp_lib_atomic_flag_test FMT_EXPORT -template -struct formatter, Char> : nested_formatter { +template struct formatter, Char> { private: - // Functor because C++11 doesn't support generic lambdas. - struct writer { - const formatter, Char>* f; - const std::complex& c; + detail::dynamic_format_specs specs_; - template - FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt { - if (c.real() != 0) { - auto format_full = detail::string_literal{}; - return fmt::format_to(out, basic_string_view(format_full), - f->nested(c.real()), f->nested(c.imag())); - } - auto format_imag = detail::string_literal{}; - return fmt::format_to(out, basic_string_view(format_imag), - f->nested(c.imag())); + template + FMT_CONSTEXPR auto do_format(const std::complex& c, + detail::dynamic_format_specs& specs, + FormatContext& ctx, OutputIt out) const + -> OutputIt { + if (c.real() != 0) { + *out++ = Char('('); + out = detail::write(out, c.real(), specs, ctx.locale()); + specs.sign = sign::plus; + out = detail::write(out, c.imag(), specs, ctx.locale()); + if (!detail::isfinite(c.imag())) *out++ = Char(' '); + *out++ = Char('i'); + *out++ = Char(')'); + return out; } - }; + out = detail::write(out, c.imag(), specs, ctx.locale()); + if (!detail::isfinite(c.imag())) *out++ = Char(' '); + *out++ = Char('i'); + return out; + } public: + FMT_CONSTEXPR auto parse(basic_format_parse_context& ctx) + -> decltype(ctx.begin()) { + if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); + return parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, + detail::type_constant::value); + } + template - auto format(const std::complex& c, FormatContext& ctx) const + auto format(const std::complex& c, FormatContext& ctx) const -> decltype(ctx.out()) { - return this->write_padded(ctx, writer{this, c}); + auto specs = specs_; + if (specs.width_ref.kind != detail::arg_id_kind::none || + specs.precision_ref.kind != detail::arg_id_kind::none) { + detail::handle_dynamic_spec(specs.width, + specs.width_ref, ctx); + detail::handle_dynamic_spec( + specs.precision, specs.precision_ref, ctx); + } + + if (specs.width == 0) return do_format(c, specs, ctx, ctx.out()); + auto buf = basic_memory_buffer(); + + auto outer_specs = format_specs(); + outer_specs.width = specs.width; + outer_specs.fill = specs.fill; + outer_specs.align = specs.align; + + specs.width = 0; + specs.fill = {}; + specs.align = align::none; + + do_format(c, specs, ctx, basic_appender(buf)); + return detail::write(ctx.out(), + basic_string_view(buf.data(), buf.size()), + outer_specs); } };