From 1d696dc280e9d2f7bf89be6819a558eacac754fe Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 17 Sep 2020 06:35:33 -0700 Subject: [PATCH] Handle exotic character types in compilation --- include/fmt/compile.h | 10 +++++++--- test/compile-test.cc | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index c68c3328..4d8caa32 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -637,9 +637,13 @@ template ::value)> FMT_INLINE std::basic_string format(const S&, Args&&... args) { - constexpr basic_string_view str = S(); - if (str.size() == 2 && str[0] == '{' && str[1] == '}') - return fmt::to_string(detail::first(args...)); +#ifdef __cpp_if_constexpr + if constexpr (std::is_same::value) { + constexpr basic_string_view str = S(); + if (str.size() == 2 && str[0] == '{' && str[1] == '}') + return fmt::to_string(detail::first(args...)); + } +#endif constexpr auto compiled = detail::compile(S()); return format(compiled, std::forward(args)...); } diff --git a/test/compile-test.cc b/test/compile-test.cc index 38f94d24..3f9fb0dc 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -149,6 +149,10 @@ TEST(CompileTest, FormatDefault) { EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), test_formattable())); } +TEST(CompileTest, FormatWideString) { + EXPECT_EQ(L"42", fmt::format(FMT_COMPILE(L"{}"), 42)); +} + TEST(CompileTest, FormatSpecs) { EXPECT_EQ("42", fmt::format(FMT_COMPILE("{:x}"), 0x42)); }