From 0b39d67103025c4b15c424ff5e2ce4ce7399edd8 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 1 Jan 2024 16:10:13 -0800 Subject: [PATCH] Remove detail::error_handler --- include/fmt/core.h | 14 ++------------ include/fmt/format.h | 4 +++- include/fmt/printf.h | 4 +--- test/scan.h | 4 ++-- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 94f3f22b..acbf292e 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -646,15 +646,6 @@ enum { // DEPRECATED! FMT_NORETURN FMT_API void throw_format_error(const char* message); - -struct error_handler { - constexpr error_handler() = default; - - // This function is intentionally not constexpr to give a compile-time error. - FMT_NORETURN void on_error(const char* message) { - throw_format_error(message); - } -}; } // namespace detail /** Throws ``format_error`` with a given message. */ @@ -1772,9 +1763,8 @@ 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); } + // This function is intentionally not constexpr to give a compile-time error. + void on_error(const char* message) { throw_format_error(message); } // Returns an iterator to the beginning of the output range. FMT_CONSTEXPR auto out() -> iterator { return out_; } diff --git a/include/fmt/format.h b/include/fmt/format.h index 97f0e1fb..fbe344f2 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -4360,7 +4360,7 @@ void vformat_to(buffer& buf, basic_string_view fmt, return; } - struct format_handler : error_handler { + struct format_handler { basic_format_parse_context parse_context; buffer_context context; @@ -4412,6 +4412,8 @@ void vformat_to(buffer& buf, basic_string_view fmt, context.advance_to(visit_format_arg(f, arg)); return begin; } + + void on_error(const char* message) { throw_format_error(message); } }; detail::parse_format_string(fmt, format_handler(out, fmt, args, loc)); } diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 07e81577..b70df5e7 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -53,9 +53,7 @@ template class basic_printf_context { return args_.get(id); } - FMT_CONSTEXPR void on_error(const char* message) { - detail::error_handler().on_error(message); - } + void on_error(const char* message) { throw_format_error(message); } }; namespace detail { diff --git a/test/scan.h b/test/scan.h index a68c77c3..91351b00 100644 --- a/test/scan.h +++ b/test/scan.h @@ -573,7 +573,7 @@ struct arg_scanner { } }; -struct scan_handler : error_handler { +struct scan_handler { private: scan_parse_context parse_ctx_; scan_context scan_ctx_; @@ -626,7 +626,7 @@ struct scan_handler : error_handler { return begin; } - void on_error(const char* message) { error_handler::on_error(message); } + void on_error(const char* message) { throw_format_error(message); } }; } // namespace detail