Fix conditional char8_t from format.h and fix -Wunused-result of [[no_discard]] begin() when in c++17

This commit is contained in:
denchat 2019-05-09 01:49:53 +07:00 committed by GitHub
parent 118d8bccc2
commit c575d56757
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2491,10 +2491,19 @@ TEST(FormatTest, FmtStringInTemplate) {
#endif // FMT_USE_CONSTEXPR #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) { TEST(FormatTest, ConstructU8StringViewFromCString) {
fmt::u8string_view s("ab"); fmt::u8string_view s("ab");
EXPECT_EQ(s.size(), 2u); 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[0], 'a');
EXPECT_EQ(data[1], 'b'); EXPECT_EQ(data[1], 'b');
} }
@ -2502,7 +2511,7 @@ TEST(FormatTest, ConstructU8StringViewFromCString) {
TEST(FormatTest, ConstructU8StringViewFromDataAndSize) { TEST(FormatTest, ConstructU8StringViewFromDataAndSize) {
fmt::u8string_view s("foobar", 3); fmt::u8string_view s("foobar", 3);
EXPECT_EQ(s.size(), 3u); 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[0], 'f');
EXPECT_EQ(data[1], 'o'); EXPECT_EQ(data[1], 'o');
EXPECT_EQ(data[2], 'o'); EXPECT_EQ(data[2], 'o');
@ -2513,7 +2522,7 @@ TEST(FormatTest, U8StringViewLiteral) {
using namespace fmt::literals; using namespace fmt::literals;
fmt::u8string_view s = "ab"_u; fmt::u8string_view s = "ab"_u;
EXPECT_EQ(s.size(), 2u); 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[0], 'a');
EXPECT_EQ(data[1], 'b'); EXPECT_EQ(data[1], 'b');
EXPECT_EQ(format("{:*^5}"_u, "🤡"_u), "**🤡**"_u); EXPECT_EQ(format("{:*^5}"_u, "🤡"_u), "**🤡**"_u);
@ -2536,6 +2545,6 @@ TEST(FormatTest, CharTraitsIsNotAmbiguous) {
char_traits<char>::char_type c; char_traits<char>::char_type c;
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
std::string s; std::string s;
begin(s); auto lval = begin(s);
#endif #endif
} }