lib/fmt: drop use of FMT_STRING

When compiling with libfmt-11.1.0 and newer the following compile errors occur:

In file included from ../src/decoder/DecoderPrint.cxx:23:
../src/client/Response.hxx: In instantiation of 'bool Response::Fmt(const S&, Args&& ...) [with S = decoder_plugin_print(Response&, const DecoderPlugin&)::<lambda()>::FMT_COMPILE_STRING; Args = {const char* const&}]':
../src/decoder/DecoderPrint.cxx:38:7:   required from here
   38 |         r.Fmt(FMT_STRING("plugin: {}\n"), plugin.name);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/client/Response.hxx:86:28: error: cannot convert 'const decoder_plugin_print(Response&, const DecoderPlugin&)::<lambda()>::FMT_COMPILE_STRING' to 'fmt::v11::string_view' {aka 'fmt::v11::basic_string_view<char>'}
   86 |                 return VFmt(format_str,
      |                        ~~~~^~~~~~~~~~~~
   87 |                             fmt::make_format_args(args...));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/client/Response.hxx:81:36: note: initializing argument 1 of 'bool Response::VFmt(fmt::v11::string_view, fmt::v11::format_args)'
   81 |         bool VFmt(fmt::string_view format_str, fmt::format_args args) noexcept;
      |                   ~~~~~~~~~~~~~~~~~^~~~~~~~~~
../src/client/Response.hxx: In instantiation of 'bool Response::Fmt(const S&, Args&& ...) [with S = decoder_plugin_print(Response&, const DecoderPlugin&)::<lambda()>::FMT_COMPILE_STRING; Args = {const char* const&}]':

The error is due to the use of FMT_STRING. The libfmt team shared the following:

    The correct way of using FMT_STRING is to wrap a format string when passing to a
    function with compile-time checks (i.e. that takes format_string) as documented
    in https://fmt.dev/11.1/api/#legacy-compile-time-checks.

    Noting that FMT_STRING is a legacy API and has been superseded by consteval-based
    API starting from version 8: https://github.com/fmtlib/fmt/releases/tag/8.0.0. It
    looks like MPD is trying to emulate {fmt}'s old way of implementing compile-time
    checks which was never properly documented because it was basically a hack. So the
    correct fix is to switch to format_string and, possibly, remove usage of FMT_STRING.

    The old way of doing compile-time checks (fmt::make_args_checked) was documented
    in https://fmt.dev/7.1/api.html#argument-lists but it looks like MPD is not using
    that API so the problematic uses of FMT_STRING have no effect and can just be removed.

The FMT_STRING has been removed in this change based on the fmt-7.1 API and now MPD is
successfully compile against the current libfmt-11.1.0 which highlighted the issue that
had been present in the codebase as it is now triggering the error, is legacy and was
not using the API for which FMT_STRING was aligned with.
This commit is contained in:
Rudi Heitbaum
2025-01-11 21:33:04 +00:00
parent b5bd294e5c
commit 9db7144d0f
25 changed files with 109 additions and 109 deletions

View File

@@ -62,7 +62,7 @@ static void
print_spl_list(Response &r, const PlaylistVector &list)
{
for (const auto &i : list) {
r.Fmt(FMT_STRING("playlist: {}\n"), i.name);
r.Fmt("playlist: {}\n", i.name);
if (!IsNegative(i.mtime))
time_print(r, "Last-Modified", i.mtime);
@@ -249,7 +249,7 @@ handle_update(Response &r, UpdateService &update,
const char *uri_utf8, bool discard)
{
unsigned ret = update.Enqueue(uri_utf8, discard);
r.Fmt(FMT_STRING("updating_db: {}\n"), ret);
r.Fmt("updating_db: {}\n", ret);
return CommandResult::OK;
}
@@ -259,7 +259,7 @@ handle_update(Response &r, Database &db,
{
unsigned id = db.Update(uri_utf8, discard);
if (id > 0) {
r.Fmt(FMT_STRING("updating_db: {}\n"), id);
r.Fmt("updating_db: {}\n", id);
return CommandResult::OK;
} else {
/* Database::Update() has returned 0 without setting
@@ -326,7 +326,7 @@ handle_getvol(Client &client, Request, Response &r)
const auto volume = partition.mixer_memento.GetVolume(partition.outputs);
if (volume >= 0)
r.Fmt(FMT_STRING("volume: {}\n"), volume);
r.Fmt("volume: {}\n", volume);
return CommandResult::OK;
}
@@ -391,7 +391,7 @@ handle_config(Client &client, [[maybe_unused]] Request args, Response &r)
const Storage *storage = client.GetStorage();
if (storage != nullptr) {
const auto path = storage->MapUTF8("");
r.Fmt(FMT_STRING("music_directory: {}\n"), path);
r.Fmt("music_directory: {}\n", path);
}
#endif
@@ -406,7 +406,7 @@ handle_idle(Client &client, Request args, Response &r)
unsigned event = idle_parse_name(i);
if (event == 0) {
r.FmtError(ACK_ERROR_ARG,
FMT_STRING("Unrecognized idle event: {}"),
"Unrecognized idle event: {}",
i);
return CommandResult::ERROR;
}