From bbbbef8db0524b975ebecee04d4956408c138d75 Mon Sep 17 00:00:00 2001 From: Michael Winterberg Date: Wed, 20 Mar 2019 16:19:57 -0700 Subject: [PATCH 1/2] Added missing typename to FMT_STRING. This is so that FMT_STRING can be used in a template. --- include/fmt/format.h | 3 ++- test/format-test.cc | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index bbc6fb42a791..0a251ce0cdfd 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3619,7 +3619,8 @@ FMT_END_NAMESPACE } \ } result; \ /* Suppress Qt Creator warning about unused operator. */ \ - (void)static_cast>(result); \ + (void)static_cast>( \ + result); \ return result; \ }() diff --git a/test/format-test.cc b/test/format-test.cc index 2e0ff199a8d2..fe149c53f21c 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2477,6 +2477,15 @@ TEST(FormatTest, VFormatTo) { #endif // FMT_USE_CONSTEXPR +template static std::string FmtToString(const T& t) { + return fmt::format(FMT_STRING("{}"), t); +} + +TEST(FormatTest, FmtStringInTemplate) { + EXPECT_EQ(FmtToString(1), "1"); + EXPECT_EQ(FmtToString(0), "0"); +} + TEST(FormatTest, ConstructU8StringViewFromCString) { fmt::u8string_view s("ab"); EXPECT_EQ(s.size(), 2u); From 3c023d6e1ed6d45685b8a02fdc384e3dad3014ae Mon Sep 17 00:00:00 2001 From: Michael Winterberg Date: Wed, 20 Mar 2019 16:57:28 -0700 Subject: [PATCH 2/2] exclude FMT_STRING in template test if relaxed constexpr isn't supported. --- test/format-test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index fe149c53f21c..1b5a2f7120a5 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2475,8 +2475,6 @@ TEST(FormatTest, VFormatTo) { EXPECT_EQ(L"42", w); } -#endif // FMT_USE_CONSTEXPR - template static std::string FmtToString(const T& t) { return fmt::format(FMT_STRING("{}"), t); } @@ -2486,6 +2484,8 @@ TEST(FormatTest, FmtStringInTemplate) { EXPECT_EQ(FmtToString(0), "0"); } +#endif // FMT_USE_CONSTEXPR + TEST(FormatTest, ConstructU8StringViewFromCString) { fmt::u8string_view s("ab"); EXPECT_EQ(s.size(), 2u);