Handle const-qualified named arguments

A named argument that arrives const-qualified was not recognized by
is_named_arg, silently dropping its name. This happens both when a
named argument is passed through an intermediate function returning
const T& (https://github.com/fmtlib/fmt/issues/4866) and in fmt's own
compiled format path, which passes arguments as const T&.

Make is_named_arg and is_static_named_arg see through top-level const so
the name is preserved instead of dropped.
This commit is contained in:
Victor Zverovich
2026-07-28 15:42:33 -07:00
parent caf5e48b1c
commit 26c01df3bd
3 changed files with 18 additions and 5 deletions
+4
View File
@@ -163,6 +163,10 @@ TEST(compile_test, named) {
fmt::format(FMT_COMPILE("{a0} {a1}"), "a0"_a = 41, "a1"_a = 43));
EXPECT_EQ("41 43",
fmt::format(FMT_COMPILE("{a1} {a0}"), "a0"_a = 43, "a1"_a = 41));
// A statically-named argument with a format spec compiles to spec_field,
// which passes the argument to make_format_args as const (#4866).
EXPECT_EQ("4.2", fmt::format(FMT_COMPILE("{arg:3.1f}"), "arg"_a = 4.2));
# endif
}