From 2db638f20a6fbc327a58a26a3d0fbb58a2405417 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 31 Dec 2023 07:37:59 -0800 Subject: [PATCH] Cleanup error handling --- include/fmt/core.h | 2 ++ include/fmt/format.h | 42 +++++++++++++++--------------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 1e0503db5739b..6fa22d3a2c1b1 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -644,6 +644,7 @@ enum { pointer_set = set(type::pointer_type) }; +// DEPRECATED! FMT_NORETURN FMT_API void throw_format_error(const char* message); struct error_handler { @@ -1762,6 +1763,7 @@ template class basic_format_context { } auto args() const -> const format_args& { return args_; } + // DEPRECATED! FMT_CONSTEXPR auto error_handler() -> detail::error_handler { return {}; } void on_error(const char* message) { error_handler().on_error(message); } diff --git a/include/fmt/format.h b/include/fmt/format.h index ded5d51341e43..445c1d9a0ce88 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3813,51 +3813,41 @@ template struct custom_formatter { template void operator()(T) const {} }; -template class width_checker { - public: - explicit FMT_CONSTEXPR width_checker(ErrorHandler& eh) : handler_(eh) {} - +struct width_checker { template ::value)> FMT_CONSTEXPR auto operator()(T value) -> unsigned long long { - if (is_negative(value)) handler_.on_error("negative width"); + if (is_negative(value)) throw_format_error("negative width"); return static_cast(value); } template ::value)> FMT_CONSTEXPR auto operator()(T) -> unsigned long long { - handler_.on_error("width is not integer"); + throw_format_error("width is not integer"); return 0; } - - private: - ErrorHandler& handler_; }; -template class precision_checker { - public: - explicit FMT_CONSTEXPR precision_checker(ErrorHandler& eh) : handler_(eh) {} +struct precision_checker { + constexpr precision_checker() {} template ::value)> FMT_CONSTEXPR auto operator()(T value) -> unsigned long long { - if (is_negative(value)) handler_.on_error("negative precision"); + if (is_negative(value)) throw_format_error("negative precision"); return static_cast(value); } template ::value)> FMT_CONSTEXPR auto operator()(T) -> unsigned long long { - handler_.on_error("precision is not integer"); + throw_format_error("precision is not integer"); return 0; } - - private: - ErrorHandler& handler_; }; -template