[PATCH 1/6] libstdc++: port away from is_trivial in string classes

Jonathan Wakely jwakely@redhat.com
Mon Dec 9 13:09:05 GMT 2024


On 09/12/24 13:06 +0100, Giuseppe D'Angelo wrote:
>Hello,
>
>This is a series of commits that will end up with the deprecation of 
>the is_trivial type trait in C++26 (P3247R2).
>
>Existing usages in libstdc+++ need to be ported away, either to the 
>direct replacement (is_trivially_copyable && 
>is_trivially_default_constructible) or, when possible, to more 
>specific checks (as "is_trivially_copyable" is a check which suffers 
>from the same flaws of "is_trivial").
>
>I've split the work in multiple smaller commits for ease of review 
>(and amendment in case I get something wrong).

Thanks, I'll amend the ChangeLog entry as noted below and then
test+push this. I'll review the rest of the patch series too.

When submitting patches please state how/where it was tested, just so
the mailing list archives have a record that it was tested, and on
which target. I typically just say "Tested x86_64-linux" as a
shorthand for x86_64-pc-linux-gnu because I'm too lazy to type it all,
and everybody knows what I mean.

>Thanks,
>-- 
>Giuseppe D'Angelo

>From 1dcceca767df8e403bffd82a0d5e08d343bf33c5 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 1/6] 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

Capital letter for "Add".

>	  char-like type.

N.B. this should be aligned to the '*' not the 'include'.

>	* include/std/string_view: port away from is_trivial.

Capital letter for "Port".

>
>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 17b973c8b45..8369c24d3ae 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>);

This only enables the assertion for C++20 and later, but I think
that's fine.



>       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 96350f96b3c..493edec26dc 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:
>-- 
>2.34.1
>





More information about the Libstdc++ mailing list