From d04c9801a7513746c606a2c1e3af1348bb910aa4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 1 Feb 2026 19:43:51 -0800 Subject: [PATCH] Dedup compile check enforcement --- include/fmt/base.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index c9c407cc..67ec373e 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2314,6 +2314,15 @@ template struct native_formatter { -> decltype(ctx.out()); }; +template constexpr bool enforce_compile_checks() { +#ifdef FMT_ENFORCE_COMPILE_STRING + static_assert( + FMT_USE_CONSTEVAL && B, + "FMT_ENFORCE_COMPILE_STRING requires format strings to use FMT_STRING"); +#endif + return true; +} + template constexpr auto is_locking() -> bool { return locking>::value; } @@ -2630,11 +2639,8 @@ template struct fstring { std::is_reference::value)...>() == 0, "passing views as lvalues is disallowed"); if (FMT_USE_CONSTEVAL) parse_format_string(s, checker(s, arg_pack())); -#ifdef FMT_ENFORCE_COMPILE_STRING - static_assert( - FMT_USE_CONSTEVAL && sizeof(s) != 0, - "FMT_ENFORCE_COMPILE_STRING requires format strings to use FMT_STRING"); -#endif + constexpr bool unused = detail::enforce_compile_checks(); + (void)unused; } template ::value)> @@ -2642,11 +2648,8 @@ template struct fstring { auto sv = string_view(str); if (FMT_USE_CONSTEVAL) detail::parse_format_string(sv, checker(sv, arg_pack())); -#ifdef FMT_ENFORCE_COMPILE_STRING - static_assert( - FMT_USE_CONSTEVAL && sizeof(s) != 0, - "FMT_ENFORCE_COMPILE_STRING requires format strings to use FMT_STRING"); -#endif + constexpr bool unused = detail::enforce_compile_checks(); + (void)unused; } template ::value&&