From 00ee881811f64f261465b39abd3c9c278be584b6 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Date: Mon, 9 Dec 2024 01:43:27 +0100 Subject: [PATCH] libstdc++: port away from is_trivial in string classes 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 | 3 +++ libstdc++-v3/include/std/string_view | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 17b973c8b45c..8369c24d3ae3 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -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; diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index 96350f96b3c0..493edec26dc8 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -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: -- GitLab