From e4728409e7fabe0eb6238da165f9c546b93f1143 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 6 Sep 2021 16:42:17 -0700 Subject: [PATCH] Use throw_format_error in more places to reduce bloat --- include/fmt/core.h | 6 +++--- include/fmt/format-inl.h | 8 ++++---- include/fmt/format.h | 10 +++------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index f69f8220..4cfa00bf 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -569,12 +569,14 @@ FMT_INLINE void check_format_string(const S&) { template ::value)> void check_format_string(S); +FMT_NORETURN FMT_API void throw_format_error(const char* message); + struct error_handler { constexpr error_handler() = default; constexpr error_handler(const error_handler&) = default; // This function is intentionally not constexpr to give a compile-time error. - FMT_NORETURN FMT_API void on_error(const char* message); + void on_error(const char* message) { throw_format_error(message); } }; FMT_END_DETAIL_NAMESPACE @@ -1922,8 +1924,6 @@ using sign_t = sign::type; FMT_BEGIN_DETAIL_NAMESPACE -void throw_format_error(const char* message); - // Workaround an array initialization issue in gcc 4.8. template struct fill_t { private: diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index d2acdabd..ddd85182 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -40,6 +40,10 @@ FMT_FUNC void assert_fail(const char* file, int line, const char* message) { std::terminate(); } +FMT_FUNC void throw_format_error(const char* message) { + FMT_THROW(format_error(message)); +} + #ifndef _MSC_VER # define FMT_SNPRINTF snprintf #else // _MSC_VER @@ -2563,10 +2567,6 @@ FMT_FUNC void format_system_error(detail::buffer& out, int error_code, format_error_code(out, error_code, message); } -FMT_FUNC void detail::error_handler::on_error(const char* message) { - FMT_THROW(format_error(message)); -} - FMT_FUNC void report_system_error(int error_code, const char* message) FMT_NOEXCEPT { report_error(format_system_error, error_code, message); diff --git a/include/fmt/format.h b/include/fmt/format.h index 4c14c0ba..86afaefe 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -841,10 +841,6 @@ constexpr auto compile_string_to_view(detail::std_string_view s) FMT_BEGIN_DETAIL_NAMESPACE -inline void throw_format_error(const char* message) { - FMT_THROW(format_error(message)); -} - template struct is_integral : std::is_integral {}; template <> struct is_integral : std::true_type {}; template <> struct is_integral : std::true_type {}; @@ -1604,7 +1600,7 @@ FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg arg, case presentation_type::chr: return write_char(out, static_cast(abs_value), specs); default: - FMT_THROW(format_error("invalid type specifier")); + throw_format_error("invalid type specifier"); } return out; } @@ -1926,7 +1922,7 @@ auto write(OutputIt out, T value, basic_format_specs specs, : 6; if (fspecs.format == float_format::exp) { if (precision == max_value()) - FMT_THROW(format_error("number is too big")); + throw_format_error("number is too big"); else ++precision; } @@ -2048,7 +2044,7 @@ template FMT_CONSTEXPR_CHAR_TRAITS auto write(OutputIt out, const Char* value) -> OutputIt { if (!value) { - FMT_THROW(format_error("string pointer is null")); + throw_format_error("string pointer is null"); } else { auto length = std::char_traits::length(value); out = write(out, basic_string_view(value, length));