Use throw_format_error in more places to reduce bloat

This commit is contained in:
Victor Zverovich 2021-09-06 16:42:17 -07:00
parent e3ebf366a6
commit e4728409e7
3 changed files with 10 additions and 14 deletions

View File

@ -569,12 +569,14 @@ FMT_INLINE void check_format_string(const S&) {
template <typename..., typename S, FMT_ENABLE_IF(is_compile_string<S>::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 <typename Char> struct fill_t {
private:

View File

@ -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<char>& 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);

View File

@ -841,10 +841,6 @@ constexpr auto compile_string_to_view(detail::std_string_view<Char> s)
FMT_BEGIN_DETAIL_NAMESPACE
inline void throw_format_error(const char* message) {
FMT_THROW(format_error(message));
}
template <typename T> struct is_integral : std::is_integral<T> {};
template <> struct is_integral<int128_t> : std::true_type {};
template <> struct is_integral<uint128_t> : std::true_type {};
@ -1604,7 +1600,7 @@ FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg<T> arg,
case presentation_type::chr:
return write_char(out, static_cast<Char>(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<Char> specs,
: 6;
if (fspecs.format == float_format::exp) {
if (precision == max_value<int>())
FMT_THROW(format_error("number is too big"));
throw_format_error("number is too big");
else
++precision;
}
@ -2048,7 +2044,7 @@ template <typename Char, typename OutputIt>
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<Char>::length(value);
out = write(out, basic_string_view<Char>(value, length));