diff --git a/include/fmt/format.h b/include/fmt/format.h index d802ee59..e31829e4 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2897,12 +2897,16 @@ struct formatter FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const -> decltype(ctx.out()) { - auto specs = specs_; - detail::handle_dynamic_spec(specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec( - specs.precision, specs.precision_ref, ctx); - return detail::write(ctx.out(), val, specs, ctx.locale()); + if (specs_.width_ref.kind != detail::arg_id_kind::none || + specs_.precision_ref.kind != detail::arg_id_kind::none) { + auto specs = specs_; + detail::handle_dynamic_spec(specs.width, + specs.width_ref, ctx); + detail::handle_dynamic_spec( + specs.precision, specs.precision_ref, ctx); + return detail::write(ctx.out(), val, specs, ctx.locale()); + } + return detail::write(ctx.out(), val, specs_, ctx.locale()); } private: