public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/4] libstdc++: Don't use std::__is_scalar in std::valarray initialization [PR115497]
@ 2024-06-20 15:30 Jonathan Wakely
  2024-06-20 15:30 ` [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497] Jonathan Wakely
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-20 15:30 UTC (permalink / raw)
  To: libstdc++, gcc-patches

We know that valarray's value_type must be DefaultConstructible, so we
don't need to test that. I think __is_trivial is sufficient to tell us
we can use memset to value-initialize the elements.

Tested x86_64-linux.

-- >8 --

This removes the use of the std::__is_scalar trait from <valarray>,
where it can be replaced by __is_trivial. It's used to decide whether we
can use memset to value-initialize valarray elements, but memset is
suitable for any trivial types, because value-initializing them is
equivalent to filling them with zeros.

This is another step towards removing the class templates in
<bits/cpp_type_traits.h> that conflict with Clang built-in names.

libstdc++-v3/ChangeLog:

	PR libstdc++/115497
	* include/bits/valarray_array.h (__valarray_default_construct):
	Use __is_trivial(_Tp). instead of __is_scalar<_Tp>.
---
 libstdc++-v3/include/bits/valarray_array.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h
index 66b74f9aaac..07c49ce1057 100644
--- a/libstdc++-v3/include/bits/valarray_array.h
+++ b/libstdc++-v3/include/bits/valarray_array.h
@@ -80,7 +80,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     struct _Array_default_ctor<_Tp, true>
     {
-      // For fundamental types, it suffices to say 'memset()'
+      // For trivial types, it suffices to say 'memset()'
       inline static void
       _S_do_it(_Tp* __b, _Tp* __e)
       { __builtin_memset(__b, 0, (__e - __b) * sizeof(_Tp)); }
@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline void
     __valarray_default_construct(_Tp* __b, _Tp* __e)
     {
-      _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
+      _Array_default_ctor<_Tp, __is_trivial(_Tp)>::_S_do_it(__b, __e);
     }
 
   // Turn a raw-memory into an array of _Tp filled with __t
-- 
2.45.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-21 16:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-20 15:30 [PATCH 1/4] libstdc++: Don't use std::__is_scalar in std::valarray initialization [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 3/4] libstdc++: Remove std::__is_void class template [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497] Jonathan Wakely
2024-06-21  9:31   ` Jonathan Wakely
2024-06-21 16:08     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).