]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: port away from is_trivial in string classes
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Mon, 9 Dec 2024 00:43:27 +0000 (01:43 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 10 Dec 2024 00:50:25 +0000 (00:50 +0000)
In preparation for the deprecation of is_trivial (P3247R2), stop using
it from std::string_view. Also, add the same detection to std::string
(described in [strings.general]/2).

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h: Add a static_assert on the
char-like type.
* include/std/string_view: Port away from is_trivial.

Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/std/string_view

index 17b973c8b45c5c56884649c4070af4380b2f4ca7..8369c24d3ae3eed4bce189fc45e310ecb4e1ff9a 100644 (file)
@@ -88,6 +88,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
     class basic_string
     {
 #if __cplusplus >= 202002L
+      static_assert(is_trivially_copyable_v<_CharT>
+         && is_trivially_default_constructible_v<_CharT>
+         && is_standard_layout_v<_CharT>);
       static_assert(is_same_v<_CharT, typename _Traits::char_type>);
       static_assert(is_same_v<_CharT, typename _Alloc::value_type>);
       using _Char_alloc_type = _Alloc;
index 96350f96b3c0deb667ac5bc6e38ba6baf861b03c..493edec26dc8180554ffd5dcce5457b30d9facf3 100644 (file)
@@ -108,7 +108,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     class basic_string_view
     {
       static_assert(!is_array_v<_CharT>);
-      static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>);
+      static_assert(is_trivially_copyable_v<_CharT>
+         && is_trivially_default_constructible_v<_CharT>
+         && is_standard_layout_v<_CharT>);
       static_assert(is_same_v<_CharT, typename _Traits::char_type>);
 
     public: