diff --git a/include/fmt/base.h b/include/fmt/base.h index 18c8de58..4c3233be 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2941,24 +2941,17 @@ struct compile_string {}; template using is_compile_string = std::is_base_of; -// Reports a compile-time error if S is not a valid format string. -template ::value)> -FMT_ALWAYS_INLINE void check_format_string(const S&) { -#ifdef FMT_ENFORCE_COMPILE_STRING - static_assert(is_compile_string::value, - "FMT_ENFORCE_COMPILE_STRING requires all format strings to use " - "FMT_STRING."); -#endif -} -template ::value)> -void check_format_string(S format_str) { - using char_t = typename S::char_type; - FMT_CONSTEXPR auto s = basic_string_view(format_str); - using checker = format_string_checker...>; +// Reports a compile-time error if S is not a valid format string for T. +template ::value)> +void check_format_string(S fmt) { + using char_type = typename S::char_type; + FMT_CONSTEXPR auto s = basic_string_view(fmt); + using checker = format_string_checker...>; FMT_CONSTEXPR bool error = (parse_format_string(s, checker(s)), true); ignore_unused(error); } +template ::value)> +FMT_ALWAYS_INLINE void check_format_string(S) {} // Use vformat_args and avoid type_identity to keep symbols short. template struct vformat_args { @@ -3045,6 +3038,12 @@ template class basic_format_string { detail::parse_format_string(str_, checker(s)); } #else +# ifdef FMT_ENFORCE_COMPILE_STRING + static_assert( + detail::is_compile_string::value, + "FMT_ENFORCE_COMPILE_STRING requires all format strings to use " + "FMT_STRING."); +# endif detail::check_format_string(s); #endif }