From 301ba7509e46f2a91cee76f2b7bbe6bbf9c69799 Mon Sep 17 00:00:00 2001 From: Dzmitry Neviadomski Date: Tue, 7 May 2024 15:42:23 +0300 Subject: [PATCH] fix: wrap runtime format strings with fmt::runtime fmt::format_string ctor is consteval with C++20 See https://github.com/fmtlib/fmt/issues/2438 Signed-off-by: Dzmitry Neviadomski --- libtransmission/announcer.cc | 4 ++-- libtransmission/blocklist.cc | 6 ++++-- libtransmission/net.cc | 9 +++++---- libtransmission/session.cc | 2 +- utils/create.cc | 7 ++++--- utils/remote.cc | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/libtransmission/announcer.cc b/libtransmission/announcer.cc index c536f11bfaf..2913879dbfe 100644 --- a/libtransmission/announcer.cc +++ b/libtransmission/announcer.cc @@ -890,10 +890,10 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e) tr_logAddWarnTier( tier, fmt::format( - tr_ngettext( + fmt::runtime(tr_ngettext( "Announce error: {error} (Retrying in {count} second) ({url})", "Announce error: {error} (Retrying in {count} seconds) ({url})", - interval), + interval)), fmt::arg("error", err), fmt::arg("count", interval), fmt::arg("url", announce_url))); diff --git a/libtransmission/blocklist.cc b/libtransmission/blocklist.cc index 9ae103efe2c..efd38e53ad6 100644 --- a/libtransmission/blocklist.cc +++ b/libtransmission/blocklist.cc @@ -78,7 +78,8 @@ void save(std::string_view filename, address_range_t const* ranges, size_t n_ran else { tr_logAddInfo(fmt::format( - tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", n_ranges), + fmt::runtime( + tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", n_ranges)), fmt::arg("path", tr_sys_path_basename(filename)), fmt::arg("count", n_ranges))); } @@ -400,7 +401,8 @@ void Blocklists::Blocklist::ensureLoaded() const } tr_logAddInfo(fmt::format( - tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", std::size(rules_)), + fmt::runtime( + tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", std::size(rules_))), fmt::arg("path", tr_sys_path_basename(bin_file_)), fmt::arg("count", std::size(rules_)))); } diff --git a/libtransmission/net.cc b/libtransmission/net.cc index 865ad4d9b80..1db4984082b 100644 --- a/libtransmission/net.cc +++ b/libtransmission/net.cc @@ -339,9 +339,10 @@ tr_socket_t tr_netBindTCPImpl(tr_address const& addr, tr_port port, bool suppres if (!suppress_msgs) { tr_logAddError(fmt::format( - err == EADDRINUSE ? - _("Couldn't bind port {port} on {address}: {error} ({error_code}) -- Is another copy of Transmission already running?") : - _("Couldn't bind port {port} on {address}: {error} ({error_code})"), + fmt::runtime( + err == EADDRINUSE ? + _("Couldn't bind port {port} on {address}: {error} ({error_code}) -- Is another copy of Transmission already running?") : + _("Couldn't bind port {port} on {address}: {error} ({error_code})")), fmt::arg("address", addr.display_name()), fmt::arg("port", port.host()), fmt::arg("error", tr_net_strerror(err)), @@ -707,7 +708,7 @@ int tr_address::compare(tr_address const& that) const noexcept // <=> std::string tr_socket_address::display_name(tr_address const& address, tr_port port) noexcept { - return fmt::format(address.is_ipv6() ? "[{:s}]:{:d}" : "{:s}:{:d}", address.display_name(), port.host()); + return fmt::format(fmt::runtime(address.is_ipv6() ? "[{:s}]:{:d}" : "{:s}:{:d}"), address.display_name(), port.host()); } bool tr_socket_address::is_valid_for_peers(tr_peer_from from) const noexcept diff --git a/libtransmission/session.cc b/libtransmission/session.cc index 67f76b532c6..e19c1cde835 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -1465,7 +1465,7 @@ void session_load_torrents(tr_session* session, tr_ctor* ctor, std::promise