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)); }