From 90567e92d481a5c002ee2cb2b0b519d76f3c5ef0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 23 Jul 2026 13:35:44 -0700 Subject: [PATCH] Exercise compiled field path in FMT_COMPILE format_as test The FMT_COMPILE("{}") format string takes a to_string fast path that never runs the compiled field code the format_as fix (#4836) touched. Use "[{}]" so the test actually goes through detail::field::format. --- test/compile-test.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/compile-test.cc b/test/compile-test.cc index 73e86f35..476bcb43 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -480,12 +480,13 @@ TEST(compile_test, constexpr_string_format) { } #endif // FMT_USE_CONSTEXPR_STRING -namespace { -struct compile_format_as_type { +struct type_with_format_as { int value; }; -int format_as(compile_format_as_type f) { return f.value; } -} +int format_as(type_with_format_as v) { return v.value; } + TEST(compile_test, format_as) { - EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), compile_format_as_type{42})); -} \ No newline at end of file + // Use a format string other than "{}" so that formatting goes through the + // compiled field path rather than the to_string fast path. + EXPECT_EQ("[42]", fmt::format(FMT_COMPILE("[{}]"), type_with_format_as{42})); +}