diff --git a/include/fmt/format.h b/include/fmt/format.h index 23f6c8a7f240b..2b2837055d2b6 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3580,19 +3580,19 @@ template struct arg_formatter { using context = buffer_context; iterator out; - const format_specs& specs; + const format_specs* specs; locale_ref locale; - arg_formatter(buffer_appender it, const format_specs& s) + arg_formatter(buffer_appender it, const format_specs* s) : out(it), specs(s) {} - arg_formatter(buffer_appender it, const format_specs& s, + arg_formatter(buffer_appender it, const format_specs* s, locale_ref l) : out(it), specs(s), locale(l) {} template FMT_CONSTEXPR FMT_INLINE auto operator()(T value) -> iterator { - return detail::write(out, value, specs, locale); + return detail::write(out, value, *specs, locale); } auto operator()(typename basic_format_arg::handle) -> iterator { // User-defined types are handled separately because they require access @@ -4220,7 +4220,7 @@ void vformat_to(buffer& buf, basic_string_view fmt, specs.precision, specs.precision_ref, context); if (begin == end || *begin != '}') on_error("missing '}' in format string"); - auto f = arg_formatter{context.out(), specs, context.locale()}; + auto f = arg_formatter{context.out(), &specs, context.locale()}; context.advance_to(visit_format_arg(f, arg)); return begin; } diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 8fbec12ad62c3..409e0b1faecaa 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -228,13 +228,13 @@ class printf_arg_formatter : public arg_formatter { context_type& context_; OutputIt write_null_pointer(bool is_string = false) { - auto s = this->specs; + auto s = *this->specs; s.type = presentation_type::none; return write_bytes(this->out, is_string ? "(null)" : "(nil)", s); } public: - printf_arg_formatter(OutputIt iter, format_specs& s, context_type& ctx) + printf_arg_formatter(OutputIt iter, format_specs* s, context_type& ctx) : base{iter, s}, context_(ctx) {} OutputIt operator()(monostate value) { return base::operator()(value); } @@ -244,7 +244,7 @@ class printf_arg_formatter : public arg_formatter { // MSVC2013 fails to compile separate overloads for bool and Char so use // std::is_same instead. if (std::is_same::value) { - format_specs fmt_specs = this->specs; + format_specs fmt_specs = *this->specs; if (fmt_specs.type != presentation_type::none && fmt_specs.type != presentation_type::chr) { return (*this)(static_cast(value)); @@ -269,13 +269,13 @@ class printf_arg_formatter : public arg_formatter { /** Formats a null-terminated C string. */ OutputIt operator()(const char* value) { if (value) return base::operator()(value); - return write_null_pointer(this->specs.type != presentation_type::pointer); + return write_null_pointer(this->specs->type != presentation_type::pointer); } /** Formats a null-terminated wide C string. */ OutputIt operator()(const wchar_t* value) { if (value) return base::operator()(value); - return write_null_pointer(this->specs.type != presentation_type::pointer); + return write_null_pointer(this->specs->type != presentation_type::pointer); } OutputIt operator()(basic_string_view value) { @@ -545,7 +545,7 @@ void vprintf(buffer& buf, basic_string_view format, // Format argument. out = visit_format_arg( - printf_arg_formatter(out, specs, context), arg); + printf_arg_formatter(out, &specs, context), arg); } write(out, basic_string_view(start, to_unsigned(it - start))); }