From c575d567574bc7bc04244c8b81d341bb373a4801 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 01:49:53 +0700 Subject: [PATCH] Fix conditional `char8_t` from `format.h` and fix `-Wunused-result` of [[no_discard]] begin() when in c++17 --- test/format-test.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index 3321a552..99fa2f01 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2491,10 +2491,19 @@ TEST(FormatTest, FmtStringInTemplate) { #endif // FMT_USE_CONSTEXPR +// C++20 feature test, since r346892 Clang considers char8_t a fundamental +// type in this mode. If this is the case __cpp_char8_t will be defined. +#ifndef __cpp_char8_t +// A UTF-8 code unit type. +#define CHAR8_T fmt::char8_t +#else +#define CHAR8_T char8_t +#endif + TEST(FormatTest, ConstructU8StringViewFromCString) { fmt::u8string_view s("ab"); EXPECT_EQ(s.size(), 2u); - const fmt::char8_t* data = s.data(); + const CHAR8_T* data = s.data(); EXPECT_EQ(data[0], 'a'); EXPECT_EQ(data[1], 'b'); } @@ -2502,7 +2511,7 @@ TEST(FormatTest, ConstructU8StringViewFromCString) { TEST(FormatTest, ConstructU8StringViewFromDataAndSize) { fmt::u8string_view s("foobar", 3); EXPECT_EQ(s.size(), 3u); - const fmt::char8_t* data = s.data(); + const CHAR8_T* data = s.data(); EXPECT_EQ(data[0], 'f'); EXPECT_EQ(data[1], 'o'); EXPECT_EQ(data[2], 'o'); @@ -2513,7 +2522,7 @@ TEST(FormatTest, U8StringViewLiteral) { using namespace fmt::literals; fmt::u8string_view s = "ab"_u; EXPECT_EQ(s.size(), 2u); - const fmt::char8_t* data = s.data(); + const CHAR8_T* data = s.data(); EXPECT_EQ(data[0], 'a'); EXPECT_EQ(data[1], 'b'); EXPECT_EQ(format("{:*^5}"_u, "🤡"_u), "**🤡**"_u); @@ -2536,6 +2545,6 @@ TEST(FormatTest, CharTraitsIsNotAmbiguous) { char_traits::char_type c; #if __cplusplus >= 201103L std::string s; - begin(s); + auto lval = begin(s); #endif }