diff --git a/include/fmt/base.h b/include/fmt/base.h index 13d8ef2d..8f3ec3ad 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -3014,14 +3014,15 @@ template class basic_format_string { using checker = detail::format_string_checker...>; - FMT_CONSTEXPR FMT_ALWAYS_INLINE void check() const { + FMT_CONSTEXPR FMT_ALWAYS_INLINE static void check( + basic_string_view fmt) { using namespace detail; static_assert( count<(std::is_base_of>::value && std::is_reference::value)...>() == 0, "passing views as lvalues is disallowed"); if (count_named_args() == count_statically_named_args()) - parse_format_string(str_, checker(str_)); + parse_format_string(fmt, checker(fmt)); } public: @@ -3030,7 +3031,7 @@ template class basic_format_string { FMT_ENABLE_IF( std::is_convertible>::value)> FMT_CONSTEVAL FMT_ALWAYS_INLINE basic_format_string(const S& s) : str_(s) { - if (FMT_USE_CONSTEVAL) check(); + if (FMT_USE_CONSTEVAL) check(s); #ifdef FMT_ENFORCE_COMPILE_STRING static_assert( FMT_USE_CONSTEVAL && sizeof(S) != 0, @@ -3040,13 +3041,9 @@ template class basic_format_string { } template ::value&& - std::is_constructible, - const S&>::value)> + std::is_same::value)> FMT_ALWAYS_INLINE basic_format_string(const S& s) : str_(s) { - check(); - if (FMT_USE_CONSTEVAL) return; - FMT_CONSTEXPR auto v = basic_string_view(S()); - FMT_CONSTEXPR int ignore = (detail::parse_format_string(v, checker(v)), 0); + FMT_CONSTEXPR int ignore = (check(basic_string_view(S())), 0); detail::ignore_unused(ignore); } basic_format_string(runtime_format_string fmt) : str_(fmt.str) {}