From 7f77d50baa4144936fc733fa2bbf6ef5e971d5b5 Mon Sep 17 00:00:00 2001 From: Matan Breizman Date: Thu, 1 Aug 2024 12:54:16 +0000 Subject: [PATCH] common,include,msg: fmt 11 fixes Signed-off-by: Matan Breizman --- src/common/LogEntry.h | 5 +++-- src/common/fmt_common.h | 8 ++++++++ src/include/utime_fmt.h | 2 +- src/msg/Message.h | 2 +- src/msg/async/frames_v2.cc | 2 +- src/msg/msg_fmt.h | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/LogEntry.h b/src/common/LogEntry.h index 79e6742707b1a..f79b76debaf0a 100644 --- a/src/common/LogEntry.h +++ b/src/common/LogEntry.h @@ -18,6 +18,7 @@ #include #include "include/utime.h" +#include "include/utime_fmt.h" #include "msg/msg_fmt.h" #include "msg/msg_types.h" #include "common/entity_name.h" @@ -217,14 +218,14 @@ template <> struct fmt::formatter : fmt::ostream_formatter {}; template <> struct fmt::formatter : fmt::formatter { template - auto format(const EntityName& e, FormatContext& ctx) { + auto format(const EntityName& e, FormatContext& ctx) const { return formatter::format(e.to_str(), ctx); } }; template <> struct fmt::formatter : fmt::formatter { template - auto format(const LogEntry& e, FormatContext& ctx) { + auto format(const LogEntry& e, FormatContext& ctx) const { return fmt::format_to(ctx.out(), "{} {} ({}) {} : {} [{}] {}", e.stamp, e.name, e.rank, e.seq, e.channel, LogEntry::level_to_str(e.prio), e.msg); diff --git a/src/common/fmt_common.h b/src/common/fmt_common.h index 53ce8a10ddb78..474f6fbc32477 100644 --- a/src/common/fmt_common.h +++ b/src/common/fmt_common.h @@ -38,11 +38,19 @@ template concept has_alt_fmt_print = requires(T t) { { t.alt_fmt_print(bool{}) } -> std::same_as; }; +#if FMT_VERSION >= 110000 +template +concept has_fmt_print_ctx = requires( + T t, fmt::buffered_context &ctx) { + { t.fmt_print_ctx(ctx) } -> std::same_as; +}; +#else template concept has_fmt_print_ctx = requires( T t, fmt::buffer_context &ctx) { { t.fmt_print_ctx(ctx) } -> std::same_as; }; +#endif namespace fmt { diff --git a/src/include/utime_fmt.h b/src/include/utime_fmt.h index e7a98d2097d2b..9d49d1bf050f7 100644 --- a/src/include/utime_fmt.h +++ b/src/include/utime_fmt.h @@ -23,7 +23,7 @@ struct fmt::formatter { } template - auto format(const utime_t& utime, FormatContext& ctx) + auto format(const utime_t& utime, FormatContext& ctx) const { if (utime.sec() < ((time_t)(60 * 60 * 24 * 365 * 10))) { // raw seconds. this looks like a relative time. diff --git a/src/msg/Message.h b/src/msg/Message.h index 78557f90e48f0..3e5c58ec376b4 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -617,7 +617,7 @@ struct formatter { std::ostringstream oss; m.print(oss); if (auto ver = m.get_header().version; ver) { - return fmt::format_to(ctx.out(), "{} v{}", oss.str(), ver); + return fmt::format_to(ctx.out(), "{} v{}", oss.str(), (uint32_t)ver); } else { return fmt::format_to(ctx.out(), "{}", oss.str()); } diff --git a/src/msg/async/frames_v2.cc b/src/msg/async/frames_v2.cc index e0c41fdb64c17..ef4a6ddabfb5e 100644 --- a/src/msg/async/frames_v2.cc +++ b/src/msg/async/frames_v2.cc @@ -306,7 +306,7 @@ Tag FrameAssembler::disassemble_preamble(bufferlist& preamble_bl) { sizeof(*preamble) - sizeof(preamble->crc)); if (crc != preamble->crc) { throw FrameError(fmt::format( - "bad preamble crc calculated={} expected={}", crc, preamble->crc)); + "bad preamble crc calculated={} expected={}", crc, (uint32_t)preamble->crc)); } // see calc_num_segments() diff --git a/src/msg/msg_fmt.h b/src/msg/msg_fmt.h index 41c4c6af89deb..4c6c7d2302657 100644 --- a/src/msg/msg_fmt.h +++ b/src/msg/msg_fmt.h @@ -15,7 +15,7 @@ struct fmt::formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template - auto format(const entity_name_t& addr, FormatContext& ctx) + auto format(const entity_name_t& addr, FormatContext& ctx) const { if (addr.is_new() || addr.num() < 0) { return fmt::format_to(ctx.out(), "{}.?", addr.type_str()); -- 2.39.5