From 5b202be5e09de0604c10e05f9de6f582bfcfe944 Mon Sep 17 00:00:00 2001 From: Radek Brich Date: Wed, 30 Nov 2022 14:00:32 +0100 Subject: [PATCH] fix #3105 - Compile-time error when mixing named argument with automatic indexing --- include/fmt/core.h | 2 +- test/format-test.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 5b8bf765f5f8..d3751a193191 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2984,7 +2984,7 @@ class format_string_checker { #if FMT_USE_NONTYPE_TEMPLATE_ARGS auto index = get_arg_index_by_name(id); if (index == invalid_arg_index) on_error("named argument is not found"); - return context_.check_arg_id(index), index; + return index; #else (void)id; on_error("compile-time checks for named arguments require C++20 support"); diff --git a/test/format-test.cc b/test/format-test.cc index 4e56bf69dff5..b172069e6dab 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1907,6 +1907,7 @@ TEST(format_test, compile_time_string) { EXPECT_EQ("", fmt::format(FMT_STRING(""))); EXPECT_EQ("", fmt::format(FMT_STRING(""), "arg"_a = 42)); EXPECT_EQ("42", fmt::format(FMT_STRING("{answer}"), "answer"_a = Answer())); + EXPECT_EQ("1 2", fmt::format(FMT_STRING("{} {two}"), 1, "two"_a = 2)); #endif (void)static_with_null;