From 683a74501ffb541ab8687eab6e1f03d94f542e3a Mon Sep 17 00:00:00 2001 From: Alexey Ochapov Date: Wed, 2 Dec 2020 18:14:57 +0300 Subject: [PATCH] fix formatting with empty compiled format string (#2042) --- include/fmt/compile.h | 2 +- test/compile-test.cc | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 0f7a9005..affd793e 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -643,7 +643,7 @@ FMT_INLINE std::basic_string format(const S&, #ifdef __cpp_if_constexpr if constexpr (std::is_same::value) { constexpr basic_string_view str = S(); - if (str.size() == 2 && str[0] == '{' && str[1] == '}') + if constexpr (str.size() == 2 && str[0] == '{' && str[1] == '}') return fmt::to_string(detail::first(args...)); } #endif diff --git a/test/compile-test.cc b/test/compile-test.cc index 660f4fb1..7ae28772 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -173,6 +173,10 @@ TEST(CompileTest, TextAndArg) { EXPECT_EQ(">>>42<<<", fmt::format(FMT_COMPILE(">>>{}<<<"), 42)); EXPECT_EQ("42!", fmt::format(FMT_COMPILE("{}!"), 42)); } + +TEST(CompileTest, Empty) { + EXPECT_EQ("", fmt::format(FMT_COMPILE(""))); +} #endif #if __cplusplus >= 202002L