diff --git a/include/fmt/format.h b/include/fmt/format.h index 7e5b0464..93c0ed1a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3001,12 +3001,10 @@ struct dynamic_formatter { template inline typename basic_context::format_arg basic_context::get_arg(basic_string_view name) { - if (this->check_no_auto_index()) { - map_.init(this->args()); - if (const format_arg *arg = map_.find(name)) - return *arg; - this->on_error("argument not found"); - } + map_.init(this->args()); + if (const format_arg *arg = map_.find(name)) + return *arg; + this->on_error("argument not found"); return format_arg(); } diff --git a/test/format-test.cc b/test/format-test.cc index 5712b46f..916dcc47 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -488,6 +488,7 @@ TEST(FormatterTest, NamedArg) { EXPECT_THROW_MSG(format("{a}"), format_error, "argument not found"); EXPECT_EQ(" -42", format("{0:{width}}", -42, fmt::arg("width", 4))); EXPECT_EQ("st", format("{0:.{precision}}", "str", fmt::arg("precision", 2))); + EXPECT_EQ("1 2", format("{} {two}", 1, fmt::arg("two", 2))); } TEST(FormatterTest, AutoArgIndex) {