mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 11:14:41 +00:00
Cleanup compile-time check
This commit is contained in:
parent
53316903e6
commit
8eda3c8e90
@ -2941,24 +2941,17 @@ struct compile_string {};
|
|||||||
template <typename S>
|
template <typename S>
|
||||||
using is_compile_string = std::is_base_of<compile_string, S>;
|
using is_compile_string = std::is_base_of<compile_string, S>;
|
||||||
|
|
||||||
// Reports a compile-time error if S is not a valid format string.
|
// Reports a compile-time error if S is not a valid format string for T.
|
||||||
template <typename..., typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
|
template <typename... T, typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
|
||||||
FMT_ALWAYS_INLINE void check_format_string(const S&) {
|
void check_format_string(S fmt) {
|
||||||
#ifdef FMT_ENFORCE_COMPILE_STRING
|
using char_type = typename S::char_type;
|
||||||
static_assert(is_compile_string<S>::value,
|
FMT_CONSTEXPR auto s = basic_string_view<char_type>(fmt);
|
||||||
"FMT_ENFORCE_COMPILE_STRING requires all format strings to use "
|
using checker = format_string_checker<char_type, remove_cvref_t<T>...>;
|
||||||
"FMT_STRING.");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
template <typename... Args, typename S,
|
|
||||||
FMT_ENABLE_IF(is_compile_string<S>::value)>
|
|
||||||
void check_format_string(S format_str) {
|
|
||||||
using char_t = typename S::char_type;
|
|
||||||
FMT_CONSTEXPR auto s = basic_string_view<char_t>(format_str);
|
|
||||||
using checker = format_string_checker<char_t, remove_cvref_t<Args>...>;
|
|
||||||
FMT_CONSTEXPR bool error = (parse_format_string<true>(s, checker(s)), true);
|
FMT_CONSTEXPR bool error = (parse_format_string<true>(s, checker(s)), true);
|
||||||
ignore_unused(error);
|
ignore_unused(error);
|
||||||
}
|
}
|
||||||
|
template <typename..., typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
|
||||||
|
FMT_ALWAYS_INLINE void check_format_string(S) {}
|
||||||
|
|
||||||
// Use vformat_args and avoid type_identity to keep symbols short.
|
// Use vformat_args and avoid type_identity to keep symbols short.
|
||||||
template <typename Char = char> struct vformat_args {
|
template <typename Char = char> struct vformat_args {
|
||||||
@ -3045,6 +3038,12 @@ template <typename Char, typename... Args> class basic_format_string {
|
|||||||
detail::parse_format_string<true>(str_, checker(s));
|
detail::parse_format_string<true>(str_, checker(s));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
# ifdef FMT_ENFORCE_COMPILE_STRING
|
||||||
|
static_assert(
|
||||||
|
detail::is_compile_string<S>::value,
|
||||||
|
"FMT_ENFORCE_COMPILE_STRING requires all format strings to use "
|
||||||
|
"FMT_STRING.");
|
||||||
|
# endif
|
||||||
detail::check_format_string<Args...>(s);
|
detail::check_format_string<Args...>(s);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user