From 7fb8d33f9d073222ed867726f8d3121312c690c5 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 9 Aug 2022 15:51:10 -0700 Subject: [PATCH] Fix compile-time width/precision type check --- include/fmt/core.h | 5 ++++- test/format-test.cc | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 467fdb86..13a0edf2 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2948,7 +2948,10 @@ class format_string_checker { basic_string_view format_str, ErrorHandler eh) : context_(format_str, num_args, types_, eh), parse_funcs_{&parse_format_specs...}, - types_{type_constant::value...} {} + types_{ + mapped_type_constant>::value...} { + } FMT_CONSTEXPR void on_text(const Char*, const Char*) {} diff --git a/test/format-test.cc b/test/format-test.cc index 5d8f19f3..f3bdb464 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -895,6 +895,7 @@ TEST(format_test, runtime_width) { fmt::format("{0:{1}}", reinterpret_cast(0xcafe), 10)); EXPECT_EQ("x ", fmt::format("{0:{1}}", 'x', 11)); EXPECT_EQ("str ", fmt::format("{0:{1}}", "str", 12)); + EXPECT_EQ(fmt::format("{:{}}", 42, short(4)), " 42"); } TEST(format_test, precision) {