diff --git a/include/fmt/core.h b/include/fmt/core.h index 40c4ddb0..e83800ce 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1713,7 +1713,7 @@ template class basic_format_args { } template int get_id(basic_string_view name) const { - if (!has_named_args()) return {}; + if (!has_named_args()) return -1; const auto& named_args = (is_packed() ? values_[-1] : args_[-1].value_).named_args; for (size_t i = 0; i < named_args.size; ++i) { diff --git a/test/format-test.cc b/test/format-test.cc index 978feef2..2a25566c 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -543,7 +543,6 @@ TEST(FormatterTest, ManyArgs) { TEST(FormatterTest, NamedArg) { EXPECT_EQ("1/a/A", format("{_1}/{a_}/{A_}", fmt::arg("a_", 'a'), fmt::arg("A_", "A"), fmt::arg("_1", 1))); - 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))); @@ -553,6 +552,8 @@ TEST(FormatterTest, NamedArg) { fmt::arg("i", 0), fmt::arg("j", 0), fmt::arg("k", 0), fmt::arg("l", 0), fmt::arg("m", 0), fmt::arg("n", 0), fmt::arg("o", 0), fmt::arg("p", 0))); + EXPECT_THROW_MSG(format("{a}"), format_error, "argument not found"); + EXPECT_THROW_MSG(format("{a}", 42), format_error, "argument not found"); } TEST(FormatterTest, AutoArgIndex) {