From 499047e1325be89325de76ae7b2f421911f54844 Mon Sep 17 00:00:00 2001 From: Alexey Ochapov Date: Tue, 16 Feb 2021 07:16:57 +0300 Subject: [PATCH] fix incorrect indexing mode for named args, update tests --- include/fmt/compile.h | 5 +---- test/compile-test.cc | 20 ++++++++------------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 30ee85df..39b8969c 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -668,11 +668,8 @@ constexpr auto compile_format_string(S format_str) { format_str); } } else if constexpr (arg_id_result.arg_id.kind == arg_id_kind::name) { - static_assert( - ID != manual_indexing_id, - "cannot switch from manual to automatic argument indexing"); if constexpr (c == '}') { - return parse_tail( + return parse_tail( runtime_named_field{arg_id_result.arg_id.val.name}, format_str); } else if constexpr (c == ':') { diff --git a/test/compile-test.cc b/test/compile-test.cc index ce23c2f5..ed34429d 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -262,18 +262,14 @@ TEST(CompileTest, Named) { EXPECT_EQ("foobar", fmt::format(FMT_COMPILE("{a0}{a1}"), fmt::arg("a0", "foo"), fmt::arg("a1", "bar"))); - EXPECT_EQ("foobar", - fmt::format(/*FMT_COMPILE(*/ "{}{a1}" /*)*/, fmt::arg("a0", "foo"), - fmt::arg("a1", "bar"))); - EXPECT_EQ("foofoo", - fmt::format(/*FMT_COMPILE(*/ "{a0}{}" /*)*/, fmt::arg("a0", "foo"), - fmt::arg("a1", "bar"))); - EXPECT_EQ("foobar", - fmt::format(/*FMT_COMPILE(*/ "{a0}{1}" /*)*/, fmt::arg("a0", "foo"), - fmt::arg("a1", "bar"))); - EXPECT_EQ("foobar", - fmt::format(/*FMT_COMPILE(*/ "{0}{a1}" /*)*/, fmt::arg("a0", "foo"), - fmt::arg("a1", "bar"))); + EXPECT_EQ("foobar", fmt::format(FMT_COMPILE("{}{a1}"), fmt::arg("a0", "foo"), + fmt::arg("a1", "bar"))); + EXPECT_EQ("foofoo", fmt::format(FMT_COMPILE("{a0}{}"), fmt::arg("a0", "foo"), + fmt::arg("a1", "bar"))); + EXPECT_EQ("foobar", fmt::format(FMT_COMPILE("{0}{a1}"), fmt::arg("a0", "foo"), + fmt::arg("a1", "bar"))); + EXPECT_EQ("foobar", fmt::format(FMT_COMPILE("{a0}{1}"), fmt::arg("a0", "foo"), + fmt::arg("a1", "bar"))); EXPECT_EQ("foobar", fmt::format(FMT_COMPILE("{}{a1}"), "foo", fmt::arg("a1", "bar")));