diff --git a/include/fmt/format.h b/include/fmt/format.h index ed9ebb7d..0b74fb66 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1741,9 +1741,9 @@ constexpr void handle_integral_type_spec(char c, Handler &&handler) { } template -class int_type_checker { +class int_type_checker : private ErrorHandler { public: - constexpr int_type_checker(ErrorHandler &eh) : eh_(eh) {} + constexpr int_type_checker(ErrorHandler eh) : ErrorHandler(eh) {} constexpr void on_dec() {} constexpr void on_hex() {} @@ -1752,11 +1752,8 @@ class int_type_checker { constexpr void on_num() {} constexpr void on_error() { - eh_.on_error("invalid type specifier"); + ErrorHandler::on_error("invalid type specifier"); } - - private: - ErrorHandler &eh_; }; template @@ -2003,6 +2000,8 @@ class parse_context : public ErrorHandler { } void check_arg_id(basic_string_view) {} + + constexpr ErrorHandler error_handler() const { return *this; } }; template @@ -3770,8 +3769,10 @@ struct formatter< handler(handler_type(specs_, ctx), internal::get_type()); it = parse_format_specs(it, handler); if (std::is_integral::value) { + using type_checker = + internal::int_type_checker; handle_integral_type_spec( - specs_.type(), internal::int_type_checker(ctx)); + specs_.type(), type_checker(ctx.error_handler())); } return pointer_from(it); }