[libcxx-commits] [libcxx] 28f82be - [libc++] [C++20] [P0482] Add missing tests and synopses for char8_t.
Marek Kurdej via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Mar 23 10:45:37 PDT 2021
Author: Marek Kurdej
Date: 2021-03-23T18:45:31+01:00
New Revision: 28f82bec7fa1bbe99ece9149adb3563041914d86
URL: https://github.com/llvm/llvm-project/commit/28f82bec7fa1bbe99ece9149adb3563041914d86
DIFF: https://github.com/llvm/llvm-project/commit/28f82bec7fa1bbe99ece9149adb3563041914d86.diff
LOG: [libc++] [C++20] [P0482] Add missing tests and synopses for char8_t.
Left to finish P0482:
* <cuchar> header.
* Parts of <memory_resource> concerning char8_t. Also, tests for hash<pmr::*string>.
Reviewed By: ldionne, #libc, Quuxplusone
Differential Revision: https://reviews.llvm.org/D99184
Added:
Modified:
libcxx/include/__string
libcxx/include/iosfwd
libcxx/include/string
libcxx/include/string_view
libcxx/test/std/language.support/support.limits/limits/is_specialized.pass.cpp
libcxx/test/std/strings/basic.string.hash/char_type_hash.fail.cpp
libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp
libcxx/test/std/strings/string.view/string.view.hash/char_type.hash.fail.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__string b/libcxx/include/__string
index 5b340d03ad86..01f583d27d7e 100644
--- a/libcxx/include/__string
+++ b/libcxx/include/__string
@@ -47,7 +47,9 @@ struct char_traits
template <> struct char_traits<char>;
template <> struct char_traits<wchar_t>;
-template <> struct char_traits<char8_t>; // c++20
+template <> struct char_traits<char8_t>; // C++20
+template <> struct char_traits<char16_t>;
+template <> struct char_traits<char32_t>;
} // std
diff --git a/libcxx/include/iosfwd b/libcxx/include/iosfwd
index 0a0de99ff3a7..f60437c952cf 100644
--- a/libcxx/include/iosfwd
+++ b/libcxx/include/iosfwd
@@ -84,8 +84,11 @@ typedef basic_ofstream<wchar_t> wofstream;
typedef basic_fstream<wchar_t> wfstream;
template <class state> class fpos;
-typedef fpos<char_traits<char>::state_type> streampos;
-typedef fpos<char_traits<wchar_t>::state_type> wstreampos;
+using streampos = fpos<char_traits<char>::state_type>;
+using wstreampos = fpos<char_traits<wchar_t>::state_type>;
+using u8streampos = fpos<char_traits<char8_t>::state_type>; // C++20
+using u16streampos = fpos<char_traits<char16_t>::state_type>;
+using u32streampos = fpos<char_traits<char32_t>::state_type>;
} // std
diff --git a/libcxx/include/string b/libcxx/include/string
index 19bd22b3acf5..a5fe62572349 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -69,6 +69,9 @@ struct char_traits
template <> struct char_traits<char>;
template <> struct char_traits<wchar_t>;
+template <> struct char_traits<char8_t>; // C++20
+template <> struct char_traits<char16_t>;
+template <> struct char_traits<char32_t>;
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_string
@@ -450,6 +453,7 @@ erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
typedef basic_string<char> string;
typedef basic_string<wchar_t> wstring;
+typedef basic_string<char8_t> u8string; // C++20
typedef basic_string<char16_t> u16string;
typedef basic_string<char32_t> u32string;
@@ -494,12 +498,14 @@ wstring to_wstring(double val);
wstring to_wstring(long double val);
template <> struct hash<string>;
+template <> struct hash<u8string>; // C++20
template <> struct hash<u16string>;
template <> struct hash<u32string>;
template <> struct hash<wstring>;
basic_string<char> operator "" s( const char *str, size_t len ); // C++14
basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
+basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20
basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
diff --git a/libcxx/include/string_view b/libcxx/include/string_view
index f8c63571f3c4..6af16117ba5b 100644
--- a/libcxx/include/string_view
+++ b/libcxx/include/string_view
@@ -48,6 +48,7 @@ namespace std {
// basic_string_view typedef names
typedef basic_string_view<char> string_view;
+ typedef basic_string_view<char8_t> u8string_view; // C++20
typedef basic_string_view<char16_t> u16string_view;
typedef basic_string_view<char32_t> u32string_view;
typedef basic_string_view<wchar_t> wstring_view;
@@ -161,12 +162,14 @@ namespace std {
// 7.11, Hash support
template <class T> struct hash;
template <> struct hash<string_view>;
+ template <> struct hash<u8string_view>; // C++20
template <> struct hash<u16string_view>;
template <> struct hash<u32string_view>;
template <> struct hash<wstring_view>;
constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept;
constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept;
+ constexpr basic_string_view<char8_t> operator "" sv( const char8_t *str, size_t len ) noexcept; // C++20
constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept;
constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept;
diff --git a/libcxx/test/std/language.support/support.limits/limits/is_specialized.pass.cpp b/libcxx/test/std/language.support/support.limits/limits/is_specialized.pass.cpp
index e4546fee4bd9..369e6ae10048 100644
--- a/libcxx/test/std/language.support/support.limits/limits/is_specialized.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/limits/is_specialized.pass.cpp
@@ -46,6 +46,9 @@ int main(int, char**)
test<bool>();
test<char>();
test<wchar_t>();
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+ test<char8_t>();
+#endif
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
diff --git a/libcxx/test/std/strings/basic.string.hash/char_type_hash.fail.cpp b/libcxx/test/std/strings/basic.string.hash/char_type_hash.fail.cpp
index 94cd87b128f3..91585d0fdae5 100644
--- a/libcxx/test/std/strings/basic.string.hash/char_type_hash.fail.cpp
+++ b/libcxx/test/std/strings/basic.string.hash/char_type_hash.fail.cpp
@@ -17,6 +17,8 @@
#include <string>
+#include "test_macros.h"
+
template <class _CharT>
struct trait // copied from <__string>
{
@@ -57,12 +59,18 @@ void test() {
typedef std::basic_string<CharT, trait<CharT> > str_t;
std::hash<str_t>
h; // expected-error-re 4 {{{{call to implicitly-deleted default constructor of 'std::hash<str_t>'|implicit instantiation of undefined template}} {{.+}}}}}}
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+ // expected-error-re at -2 {{{{call to implicitly-deleted default constructor of 'std::hash<str_t>'|implicit instantiation of undefined template}} {{.+}}}}}}
+#endif
(void)h;
}
int main(int, char**) {
test<char>();
test<wchar_t>();
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+ test<char8_t>();
+#endif
test<char16_t>();
test<char32_t>();
diff --git a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp
index c634a235d22d..53e10204fbb3 100644
--- a/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp
+++ b/libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/types.pass.cpp
@@ -11,10 +11,10 @@
// template<> struct char_traits<char8_t>
-// typedef char8_t char_type;
+// typedef char8_t char_type;
// typedef unsigned int int_type;
// typedef streamoff off_type;
-// typedef u16streampos pos_type;
+// typedef u8streampos pos_type;
// typedef mbstate_t state_type;
#include <string>
@@ -29,7 +29,7 @@ int main(int, char**)
static_assert((std::is_same<std::char_traits<char8_t>::char_type, char8_t>::value), "");
static_assert((std::is_same<std::char_traits<char8_t>::int_type, unsigned int>::value), "");
static_assert((std::is_same<std::char_traits<char8_t>::off_type, std::streamoff>::value), "");
- static_assert((std::is_same<std::char_traits<char8_t>::pos_type, std::u16streampos>::value), "");
+ static_assert((std::is_same<std::char_traits<char8_t>::pos_type, std::u8streampos>::value), "");
static_assert((std::is_same<std::char_traits<char8_t>::state_type, std::mbstate_t>::value), "");
#endif
diff --git a/libcxx/test/std/strings/string.view/string.view.hash/char_type.hash.fail.cpp b/libcxx/test/std/strings/string.view/string.view.hash/char_type.hash.fail.cpp
index 5d6d152b6c59..4d645c5da166 100644
--- a/libcxx/test/std/strings/string.view/string.view.hash/char_type.hash.fail.cpp
+++ b/libcxx/test/std/strings/string.view/string.view.hash/char_type.hash.fail.cpp
@@ -18,6 +18,8 @@
#include <string_view>
#include <string> // for 'mbstate_t'
+#include "test_macros.h"
+
template <class _CharT>
struct trait // copied from <__string>
{
@@ -58,12 +60,18 @@ void test() {
typedef std::basic_string_view<CharT, trait<CharT> > strv_t;
std::hash<strv_t>
h; // expected-error-re 4 {{{{call to implicitly-deleted default constructor of 'std::hash<strv_t>'|implicit instantiation of undefined template}} {{.+}}}}}}
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+ // expected-error-re at -2 {{{{call to implicitly-deleted default constructor of 'std::hash<strv_t>'|implicit instantiation of undefined template}} {{.+}}}}}}
+#endif
(void)h;
}
int main(int, char**) {
test<char>();
test<wchar_t>();
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
+ test<char8_t>();
+#endif
test<char16_t>();
test<char32_t>();
More information about the libcxx-commits
mailing list