From 2696dc927397f49b9234e1095360f5774d5de7a1 Mon Sep 17 00:00:00 2001 From: rimathia Date: Sun, 20 Sep 2020 15:51:11 +0200 Subject: [PATCH] =?UTF-8?q?add=20forgotten=20template=20argument=20to=20ma?= =?UTF-8?q?ke=5Fformat=5Fargs=20which=20made=20some=20u=E2=80=A6=20(#1877)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add forgotten template argument to make_format_args which made some uses of FMT_COMPILE not work anymore after 54daa0864afb57e9d1, add more elaborate test cases to compile-test as regression tests * fix old-style cast which gcc on travis thankfully doesn't accept anymore * hopefully last forgotten (void*) --- include/fmt/compile.h | 3 ++- test/compile-test.cc | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 4d8caa32..13406ce2 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -444,7 +444,8 @@ template struct spec_field { OutputIt format(OutputIt out, const Args&... args) const { // This ensures that the argument type is convertile to `const T&`. const T& arg = get(args...); - const auto& vargs = make_format_args(args...); + const auto& vargs = + make_format_args>(args...); basic_format_context ctx(out, vargs); return fmt.format(arg, ctx); } diff --git a/test/compile-test.cc b/test/compile-test.cc index 3f9fb0dc..f1fd65b3 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -155,6 +155,9 @@ TEST(CompileTest, FormatWideString) { TEST(CompileTest, FormatSpecs) { EXPECT_EQ("42", fmt::format(FMT_COMPILE("{:x}"), 0x42)); + EXPECT_EQ("1.234000:0042:+3.13:str:0x3e8:X", + fmt::format(FMT_COMPILE("{:.6f}:{:04}:{:+}:{}:{}:{}"), 1.234, 42, + 3.13, "str", reinterpret_cast(1000), 'X')); } TEST(CompileTest, DynamicWidth) { @@ -163,18 +166,39 @@ TEST(CompileTest, DynamicWidth) { } TEST(CompileTest, FormatTo) { - char buf[8]; - auto end = fmt::format_to(buf, FMT_COMPILE("{}"), 42); - *end = '\0'; - EXPECT_STREQ("42", buf); + { + char buf[8]; + auto end = fmt::format_to(buf, FMT_COMPILE("{}"), 42); + *end = '\0'; + EXPECT_STREQ("42", buf); + } + { + char buf[100]; + auto end = + fmt::format_to(buf, FMT_COMPILE("{:.6f}:{:04}:{:+}:{}:{}:{}"), 1.234, + 42, 3.13, "str", reinterpret_cast(1000), 'X'); + *end = '\0'; + EXPECT_STREQ("1.234000:0042:+3.13:str:0x3e8:X", buf); + } } TEST(CompileTest, FormatToNWithCompileMacro) { - constexpr auto buffer_size = 8; - char buffer[buffer_size]; - auto res = fmt::format_to_n(buffer, buffer_size, FMT_COMPILE("{}"), 42); - *res.out = '\0'; - EXPECT_STREQ("42", buffer); + { + constexpr auto buffer_size = 8; + char buffer[buffer_size]; + auto res = fmt::format_to_n(buffer, buffer_size, FMT_COMPILE("{}"), 42); + *res.out = '\0'; + EXPECT_STREQ("42", buffer); + } + { + constexpr auto buffer_size = 100; + char buffer[buffer_size]; + auto res = fmt::format_to_n( + buffer, buffer_size, FMT_COMPILE("{:.6f}:{:04}:{:+}:{}:{}:{}"), 1.234, + 42, 3.13, "str", reinterpret_cast(1000), 'X'); + *res.out = '\0'; + EXPECT_STREQ("1.234000:0042:+3.13:str:0x3e8:X", buffer); + } } TEST(CompileTest, TextAndArg) {