Dedup throw_format_error

This commit is contained in:
Victor Zverovich
2024-01-01 18:42:23 -08:00
parent 9659f22d36
commit f4a7d40dca
2 changed files with 8 additions and 11 deletions

View File

@ -657,13 +657,10 @@ enum {
cstring_set = set(type::cstring_type), cstring_set = set(type::cstring_type),
pointer_set = set(type::pointer_type) pointer_set = set(type::pointer_type)
}; };
// DEPRECATED!
FMT_NORETURN FMT_API void throw_format_error(const char* message);
} // namespace detail } // namespace detail
/** Throws ``format_error`` with a given message. */ /** Throws ``format_error`` with a given message. */
using detail::throw_format_error; FMT_NORETURN FMT_API void throw_format_error(const char* message);
/** String's character type. */ /** String's character type. */
template <typename S> using char_t = typename detail::char_t_impl<S>::type; template <typename S> using char_t = typename detail::char_t_impl<S>::type;
@ -715,7 +712,7 @@ template <typename Char> class basic_format_parse_context {
*/ */
FMT_CONSTEXPR auto next_arg_id() -> int { FMT_CONSTEXPR auto next_arg_id() -> int {
if (next_arg_id_ < 0) { if (next_arg_id_ < 0) {
detail::throw_format_error( throw_format_error(
"cannot switch from manual to automatic argument indexing"); "cannot switch from manual to automatic argument indexing");
return 0; return 0;
} }
@ -730,7 +727,7 @@ template <typename Char> class basic_format_parse_context {
*/ */
FMT_CONSTEXPR void check_arg_id(int id) { FMT_CONSTEXPR void check_arg_id(int id) {
if (next_arg_id_ > 0) { if (next_arg_id_ > 0) {
detail::throw_format_error( throw_format_error(
"cannot switch from automatic to manual argument indexing"); "cannot switch from automatic to manual argument indexing");
return; return;
} }
@ -1068,7 +1065,7 @@ FMT_CONSTEXPR void basic_format_parse_context<Char>::do_check_arg_id(int id) {
(!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) { (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
using context = detail::compile_parse_context<Char>; using context = detail::compile_parse_context<Char>;
if (id >= static_cast<context*>(this)->num_args()) if (id >= static_cast<context*>(this)->num_args())
detail::throw_format_error("argument not found"); throw_format_error("argument not found");
} }
} }

View File

@ -36,10 +36,6 @@ FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
std::terminate(); std::terminate();
} }
FMT_FUNC void throw_format_error(const char* message) {
FMT_THROW(format_error(message));
}
FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code, FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
string_view message) noexcept { string_view message) noexcept {
// Report error code making sure that the output fits into // Report error code making sure that the output fits into
@ -127,6 +123,10 @@ FMT_FUNC auto write_loc(appender out, loc_value value,
} }
} // namespace detail } // namespace detail
FMT_FUNC void throw_format_error(const char* message) {
FMT_THROW(format_error(message));
}
template <typename Locale> typename Locale::id format_facet<Locale>::id; template <typename Locale> typename Locale::id format_facet<Locale>::id;
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR #ifndef FMT_STATIC_THOUSANDS_SEPARATOR