Skip to content

Commit

Permalink
P0482R5 char8_t: Standard library support
Browse files Browse the repository at this point in the history
gcc/cp:

2019-02-19  Tom Honermann  <tom@honermann.net>

	* name-lookup.c (get_std_name_hint): Added u8string as a name hint.

libstdc++:

2019-02-19  Tom Honermann  <tom@honermann.net>

	P0482R5 char8_t: Standard library support
	* config/abi/pre/gnu-versioned-namespace.ver (CXXABI_2.0): Add
	typeinfo symbols for char8_t.
	* config/abi/pre/gnu.ver: Add CXXABI_1.3.12.
	(GLIBCXX_3.4.26): Add symbols for specializations of
	numeric_limits and codecvt that involve char8_t.
	(CXXABI_1.3.12): Add typeinfo symbols for char8_t.
	* include/bits/atomic_base.h: Add atomic_char8_t.
	* include/bits/basic_string.h: Add std::hash<u8string> and
	operator""s(const char8_t*, size_t).
	* include/bits/c++config: Define _GLIBCXX_USE_CHAR8_T and
	__cpp_lib_char8_t.
	* include/bits/char_traits.h: Add char_traits<char8_t>.
	* include/bits/codecvt.h: Add
	codecvt<char16_t, char8_t, mbstate_t>,
	codecvt<char32_t, char8_t, mbstate_t>,
	codecvt_byname<char16_t, char8_t, mbstate_t>, and
	codecvt_byname<char32_t, char8_t, mbstate_t>.
	* include/bits/cpp_type_traits.h: Add __is_integer<char8_t> to
	recognize char8_t as an integral type.
	* include/bits/fs_path.h: (path::__is_encoded_char): Recognize
	char8_t.
	(path::u8string): Return std::u8string when char8_t support is
	enabled.
	(path::generic_u8string): Likewise.
	(path::_S_convert): Handle conversion from char8_t input.
	(path::_S_str_convert): Likewise.
	* include/bits/functional_hash.h: Add hash<char8_t>.
	* include/bits/locale_conv.h (__str_codecvt_out): Add overloads for
	char8_t.
	* include/bits/locale_facets.h (_GLIBCXX_NUM_UNICODE_FACETS): Bump
	for new char8_t specializations.
	* include/bits/localefwd.h: Add missing declarations of
	codecvt<char16_t, char, mbstate_t> and
	codecvt<char32_t, char, mbstate_t>.  Add char8_t declarations
	codecvt<char16_t, char8_t, mbstate_t> and
	codecvt<char32_t, char8_t, mbstate_t>.
	* include/bits/postypes.h: Add u8streampos
	* include/bits/stringfwd.h: Add declarations of
	char_traits<char8_t> and u8string.
	* include/c_global/cstddef: Add __byte_operand<char8_t>.
	* include/experimental/bits/fs_path.h (path::__is_encoded_char):
	Recognize char8_t.
	(path::u8string): Return std::u8string when char8_t support is
	enabled.
	(path::generic_u8string): Likewise.
	(path::_S_convert): Handle conversion from char8_t input.
	(path::_S_str_convert): Likewise.
	* include/experimental/string: Add u8string.
	* include/experimental/string_view: Add u8string_view,
	hash<experimental::u8string_view>, and
	operator""sv(const char8_t*, size_t).
	* include/std/atomic: Add atomic<char8_t> and atomic_char8_t.
	* include/std/charconv (__is_int_to_chars_type): Recognize char8_t
	as a character type.
	* include/std/limits: Add numeric_limits<char8_t>.
	* include/std/string_view: Add u8string_view,
	hash<experimental::u8string_view>, and
	operator""sv(const char8_t*, size_t).
	* include/std/type_traits: Add __is_integral_helper<char8_t>,
	__make_unsigned<char8_t>, and __make_signed<char8_t>.
	* libsupc++/atomic_lockfree_defines.h: Define
	ATOMIC_CHAR8_T_LOCK_FREE.
	* src/c++11/Makefile.am: Compile with -fchar8_t when compiling
	codecvt.cc and limits.cc so that char8_t specializations of
	numeric_limits and codecvt and emitted.
	* src/c++11/Makefile.in: Likewise.
	* src/c++11/codecvt.cc: Define members of
	codecvt<char16_t, char8_t, mbstate_t>,
	codecvt<char32_t, char8_t, mbstate_t>,
	codecvt_byname<char16_t, char8_t, mbstate_t>, and
	codecvt_byname<char32_t, char8_t, mbstate_t>.
	* src/c++11/limits.cc: Define members of
	numeric_limits<char8_t>.
	* src/c++98/Makefile.am: Compile with -fchar8_t when compiling
	locale_init.cc and localename.cc.
	* src/c++98/Makefile.in: Likewise.
	* src/c++98/locale_init.cc: Add initialization for the
	codecvt<char16_t, char8_t, mbstate_t> and
	codecvt<char32_t, char8_t, mbstate_t> facets.
	* src/c++98/localename.cc: Likewise.
	* testsuite/util/testsuite_abi.cc: Validate ABI bump.

From-SVN: r269004
  • Loading branch information
tahonermann authored and jwakely committed Feb 19, 2019
1 parent e8b3c1b commit c124af9
Show file tree
Hide file tree
Showing 38 changed files with 1,099 additions and 61 deletions.
4 changes: 4 additions & 0 deletions gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
2019-02-19 Tom Honermann <tom@honermann.net>

* name-lookup.c (get_std_name_hint): Added u8string as a name hint.

2019-02-18 Jason Merrill <jason@redhat.com>

PR c++/89336 - multiple stores in constexpr stmt.
Expand Down
1 change: 1 addition & 0 deletions gcc/cp/name-lookup.c
Expand Up @@ -5765,6 +5765,7 @@ get_std_name_hint (const char *name)
{"basic_string", "<string>", cxx98},
{"string", "<string>", cxx98},
{"wstring", "<string>", cxx98},
{"u8string", "<string>", cxx2a},
{"u16string", "<string>", cxx11},
{"u32string", "<string>", cxx11},
/* <string_view>. */
Expand Down
85 changes: 85 additions & 0 deletions libstdc++-v3/ChangeLog
@@ -1,3 +1,88 @@
2019-02-19 Tom Honermann <tom@honermann.net>

P0482R5 char8_t: Standard library support
* config/abi/pre/gnu-versioned-namespace.ver (CXXABI_2.0): Add
typeinfo symbols for char8_t.
* config/abi/pre/gnu.ver: Add CXXABI_1.3.12.
(GLIBCXX_3.4.26): Add symbols for specializations of
numeric_limits and codecvt that involve char8_t.
(CXXABI_1.3.12): Add typeinfo symbols for char8_t.
* include/bits/atomic_base.h: Add atomic_char8_t.
* include/bits/basic_string.h: Add std::hash<u8string> and
operator""s(const char8_t*, size_t).
* include/bits/c++config: Define _GLIBCXX_USE_CHAR8_T and
__cpp_lib_char8_t.
* include/bits/char_traits.h: Add char_traits<char8_t>.
* include/bits/codecvt.h: Add
codecvt<char16_t, char8_t, mbstate_t>,
codecvt<char32_t, char8_t, mbstate_t>,
codecvt_byname<char16_t, char8_t, mbstate_t>, and
codecvt_byname<char32_t, char8_t, mbstate_t>.
* include/bits/cpp_type_traits.h: Add __is_integer<char8_t> to
recognize char8_t as an integral type.
* include/bits/fs_path.h: (path::__is_encoded_char): Recognize
char8_t.
(path::u8string): Return std::u8string when char8_t support is
enabled.
(path::generic_u8string): Likewise.
(path::_S_convert): Handle conversion from char8_t input.
(path::_S_str_convert): Likewise.
* include/bits/functional_hash.h: Add hash<char8_t>.
* include/bits/locale_conv.h (__str_codecvt_out): Add overloads for
char8_t.
* include/bits/locale_facets.h (_GLIBCXX_NUM_UNICODE_FACETS): Bump
for new char8_t specializations.
* include/bits/localefwd.h: Add missing declarations of
codecvt<char16_t, char, mbstate_t> and
codecvt<char32_t, char, mbstate_t>. Add char8_t declarations
codecvt<char16_t, char8_t, mbstate_t> and
codecvt<char32_t, char8_t, mbstate_t>.
* include/bits/postypes.h: Add u8streampos
* include/bits/stringfwd.h: Add declarations of
char_traits<char8_t> and u8string.
* include/c_global/cstddef: Add __byte_operand<char8_t>.
* include/experimental/bits/fs_path.h (path::__is_encoded_char):
Recognize char8_t.
(path::u8string): Return std::u8string when char8_t support is
enabled.
(path::generic_u8string): Likewise.
(path::_S_convert): Handle conversion from char8_t input.
(path::_S_str_convert): Likewise.
* include/experimental/string: Add u8string.
* include/experimental/string_view: Add u8string_view,
hash<experimental::u8string_view>, and
operator""sv(const char8_t*, size_t).
* include/std/atomic: Add atomic<char8_t> and atomic_char8_t.
* include/std/charconv (__is_int_to_chars_type): Recognize char8_t
as a character type.
* include/std/limits: Add numeric_limits<char8_t>.
* include/std/string_view: Add u8string_view,
hash<experimental::u8string_view>, and
operator""sv(const char8_t*, size_t).
* include/std/type_traits: Add __is_integral_helper<char8_t>,
__make_unsigned<char8_t>, and __make_signed<char8_t>.
* libsupc++/atomic_lockfree_defines.h: Define
ATOMIC_CHAR8_T_LOCK_FREE.
* src/c++11/Makefile.am: Compile with -fchar8_t when compiling
codecvt.cc and limits.cc so that char8_t specializations of
numeric_limits and codecvt and emitted.
* src/c++11/Makefile.in: Likewise.
* src/c++11/codecvt.cc: Define members of
codecvt<char16_t, char8_t, mbstate_t>,
codecvt<char32_t, char8_t, mbstate_t>,
codecvt_byname<char16_t, char8_t, mbstate_t>, and
codecvt_byname<char32_t, char8_t, mbstate_t>.
* src/c++11/limits.cc: Define members of
numeric_limits<char8_t>.
* src/c++98/Makefile.am: Compile with -fchar8_t when compiling
locale_init.cc and localename.cc.
* src/c++98/Makefile.in: Likewise.
* src/c++98/locale_init.cc: Add initialization for the
codecvt<char16_t, char8_t, mbstate_t> and
codecvt<char32_t, char8_t, mbstate_t> facets.
* src/c++98/localename.cc: Likewise.
* testsuite/util/testsuite_abi.cc: Validate ABI bump.

2019-02-18 Wilco Dijkstra <wdijkstr@arm.com>

* 27_io/filesystem/operations/all.cc: Add dg-require-filesystem-ts.
Expand Down
5 changes: 5 additions & 0 deletions libstdc++-v3/config/abi/pre/gnu-versioned-namespace.ver
Expand Up @@ -301,6 +301,11 @@ CXXABI_2.0 {
_ZTSN10__cxxabiv120__si_class_type_infoE;
_ZTSN10__cxxabiv121__vmi_class_type_infoE;

# typeinfo for char8_t
_ZTIDu;
_ZTIPDu;
_ZTIPKDu;

# typeinfo for char16_t and char32_t
_ZTIDs;
_ZTIPDs;
Expand Down
20 changes: 20 additions & 0 deletions libstdc++-v3/config/abi/pre/gnu.ver
Expand Up @@ -2244,6 +2244,17 @@ GLIBCXX_3.4.26 {
# _Sp_make_shared_tag::_S_eq
_ZNSt19_Sp_make_shared_tag5_S_eqERKSt9type_info;

# numeric_limits<char8_t>
_ZNSt14numeric_limitsIDuE[5-9]*;
_ZNSt14numeric_limitsIDuE1[0-7][hirt]*;
_ZNSt14numeric_limitsIDuE1[0-7]mi*;
_ZNSt14numeric_limitsIDuE1[0-7]max_e*;

# codecvt<char16_t, char8_t, mbstate_t>, codecvt<char32_t, char8_t, mbstate_t>
_ZNKSt7codecvtID[is]Du*;
_ZNSt7codecvtID[is]Du*;
_ZT[ISV]St7codecvtID[is]Du*E;

} GLIBCXX_3.4.25;

# Symbols in the support library (libsupc++) have their own tag.
Expand Down Expand Up @@ -2535,6 +2546,15 @@ CXXABI_1.3.11 {

} CXXABI_1.3.10;

CXXABI_1.3.12 {

# typeinfo for char8_t
_ZTIDu;
_ZTIPDu;
_ZTIPKDu;

} CXXABI_1.3.11;

# Symbols in the support library (libsupc++) supporting transactional memory.
CXXABI_TM_1 {

Expand Down
1 change: 1 addition & 0 deletions libstdc++-v3/include/bits/atomic_base.h
Expand Up @@ -227,6 +227,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// atomic_ulong unsigned long
// atomic_llong long long
// atomic_ullong unsigned long long
// atomic_char8_t char8_t
// atomic_char16_t char16_t
// atomic_char32_t char32_t
// atomic_wchar_t wchar_t
Expand Down
24 changes: 24 additions & 0 deletions libstdc++-v3/include/bits/basic_string.h
Expand Up @@ -6753,6 +6753,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
#endif /* _GLIBCXX_COMPATIBILITY_CXX0X */

#ifdef _GLIBCXX_USE_CHAR8_T
/// std::hash specialization for u8string.
template<>
struct hash<u8string>
: public __hash_base<size_t, u8string>
{
size_t
operator()(const u8string& __s) const noexcept
{ return std::_Hash_impl::hash(__s.data(),
__s.length() * sizeof(char8_t)); }
};

template<>
struct __is_fast_hash<hash<u8string>> : std::false_type
{ };
#endif

/// std::hash specialization for u16string.
template<>
struct hash<u16string>
Expand Down Expand Up @@ -6805,6 +6822,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return basic_string<wchar_t>{__str, __len}; }
#endif

#ifdef _GLIBCXX_USE_CHAR8_T
_GLIBCXX_DEFAULT_ABI_TAG
inline basic_string<char8_t>
operator""s(const char8_t* __str, size_t __len)
{ return basic_string<char8_t>{__str, __len}; }
#endif

_GLIBCXX_DEFAULT_ABI_TAG
inline basic_string<char16_t>
operator""s(const char16_t* __str, size_t __len)
Expand Down
11 changes: 11 additions & 0 deletions libstdc++-v3/include/bits/c++config
Expand Up @@ -625,6 +625,17 @@ namespace std
# endif
#endif

// Unless explicitly specified, enable char8_t extensions only if the core
// language char8_t feature macro is defined.
#ifndef _GLIBCXX_USE_CHAR8_T
# ifdef __cpp_char8_t
# define _GLIBCXX_USE_CHAR8_T 1
# endif
#endif
#ifdef _GLIBCXX_USE_CHAR8_T
# define __cpp_lib_char8_t 201811
#endif

/* Define if __float128 is supported on this host. */
#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
#define _GLIBCXX_USE_FLOAT128
Expand Down
109 changes: 109 additions & 0 deletions libstdc++-v3/include/bits/char_traits.h
Expand Up @@ -507,6 +507,115 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
#endif //_GLIBCXX_USE_WCHAR_T

#ifdef _GLIBCXX_USE_CHAR8_T
template<>
struct char_traits<char8_t>
{
typedef char8_t char_type;
typedef unsigned int int_type;
typedef u8streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;

static _GLIBCXX17_CONSTEXPR void
assign(char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
{ __c1 = __c2; }

static _GLIBCXX_CONSTEXPR bool
eq(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
{ return __c1 == __c2; }

static _GLIBCXX_CONSTEXPR bool
lt(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
{ return __c1 < __c2; }

static _GLIBCXX17_CONSTEXPR int
compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
#if __cplusplus > 201402
if (__builtin_constant_p(__n)
&& __constant_char_array_p(__s1, __n)
&& __constant_char_array_p(__s2, __n))
return __gnu_cxx::char_traits<char_type>::compare(__s1, __s2, __n);
#endif
if (__n == 0)
return 0;
return __builtin_memcmp(__s1, __s2, __n);
}

static _GLIBCXX17_CONSTEXPR size_t
length(const char_type* __s)
{
#if __cplusplus > 201402
if (__constant_string_p(__s))
return __gnu_cxx::char_traits<char_type>::length(__s);
#endif
size_t __i = 0;
while (!eq(__s[__i], char_type()))
++__i;
return __i;
}

static _GLIBCXX17_CONSTEXPR const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
{
#if __cplusplus > 201402
if (__builtin_constant_p(__n)
&& __builtin_constant_p(__a)
&& __constant_char_array_p(__s, __n))
return __gnu_cxx::char_traits<char_type>::find(__s, __n, __a);
#endif
if (__n == 0)
return 0;
return static_cast<const char_type*>(__builtin_memchr(__s, __a, __n));
}

static char_type*
move(char_type* __s1, const char_type* __s2, size_t __n)
{
if (__n == 0)
return __s1;
return static_cast<char_type*>(__builtin_memmove(__s1, __s2, __n));
}

static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n)
{
if (__n == 0)
return __s1;
return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
}

static char_type*
assign(char_type* __s, size_t __n, char_type __a)
{
if (__n == 0)
return __s;
return static_cast<char_type*>(__builtin_memset(__s, __a, __n));
}

static _GLIBCXX_CONSTEXPR char_type
to_char_type(const int_type& __c) _GLIBCXX_NOEXCEPT
{ return char_type(__c); }

static _GLIBCXX_CONSTEXPR int_type
to_int_type(const char_type& __c) _GLIBCXX_NOEXCEPT
{ return int_type(__c); }

static _GLIBCXX_CONSTEXPR bool
eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOEXCEPT
{ return __c1 == __c2; }

static _GLIBCXX_CONSTEXPR int_type
eof() _GLIBCXX_NOEXCEPT
{ return static_cast<int_type>(-1); }

static _GLIBCXX_CONSTEXPR int_type
not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT
{ return eq_int_type(__c, eof()) ? 0 : __c; }
};
#endif //_GLIBCXX_USE_CHAR8_T

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

Expand Down

0 comments on commit c124af9

Please sign in to comment.