From cb8e7caf7c84a77f94395dc417b7fa020be5484e Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Fri, 3 Jan 2020 18:49:28 +0100 Subject: [PATCH] Convert 'char8_t' character sequences to 'char' sequences Otherwise, Google Test will insist on inserting 'char8_t' NTBS into 'char' streams, but basic_ostream::operator<< overloads taking 'char8_t' arguments are defined as deleted by P1423. Handling individual 'char8_t's is done inline. This fixes the compilation errors seen in C++20 mode beginning with VS2019 Update 2. Signed-off-by: Daniela Engert --- test/format-test.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index e68c1c60..cf4e764d 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2476,15 +2476,27 @@ TEST(FormatTest, FmtStringInTemplate) { using fmt::char8_t; #endif +// Convert 'char8_t' character sequences to 'char' sequences +// Otherwise GTest will insist on inserting 'char8_t' NTBS into a 'char' stream, +// but basic_ostream::operator<< overloads taking 'char8_t' arguments +// are defined as deleted by P1423. +// Handling individual 'char8_t's is done inline. +std::string from_u8str(const std::basic_string& str) { + return std::string(str.begin(), str.end()); +} +std::string from_u8str(const fmt::basic_string_view& str) { + return std::string(str.begin(), str.end()); +} + #if FMT_USE_USER_DEFINED_LITERALS TEST(FormatTest, U8StringViewLiteral) { using namespace fmt::literals; fmt::basic_string_view s = "ab"_u; EXPECT_EQ(s.size(), 2u); const char8_t* data = s.data(); - EXPECT_EQ(data[0], 'a'); - EXPECT_EQ(data[1], 'b'); - EXPECT_EQ(format("{:*^5}"_u, "🤡"_u), "**🤡**"_u); + EXPECT_EQ(char(data[0]), 'a'); + EXPECT_EQ(char(data[1]), 'b'); + EXPECT_EQ(from_u8str(format("{:*^5}"_u, "🤡"_u)), from_u8str("**🤡**"_u)); } #endif @@ -2533,5 +2545,5 @@ TEST(FormatTest, FormatUTF8Precision) { auto result = fmt::format(format, str); EXPECT_EQ(fmt::internal::count_code_points(result), 4); EXPECT_EQ(result.size(), 5); - EXPECT_EQ(result, str.substr(0, 5)); + EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5))); }