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.
This commit is contained in:
Victor Zverovich 2026-07-23 13:35:44 -07:00
parent c851fbe658
commit 90567e92d4

View File

@ -480,12 +480,13 @@ TEST(compile_test, constexpr_string_format) {
} }
#endif // FMT_USE_CONSTEXPR_STRING #endif // FMT_USE_CONSTEXPR_STRING
namespace { struct type_with_format_as {
struct compile_format_as_type {
int value; 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) { TEST(compile_test, format_as) {
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), compile_format_as_type{42})); // 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}));
}