public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9118] libstdc++: Ensure std::span and std::string_view are trivially copyable (P2251R1)
@ 2021-10-12 10:59 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-10-12 10:59 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:b8fccd58eedcea514542b1c530924aea8948c6ea
commit r11-9118-gb8fccd58eedcea514542b1c530924aea8948c6ea
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Oct 5 16:38:42 2021 +0100
libstdc++: Ensure std::span and std::string_view are trivially copyable (P2251R1)
The recently approved P2251R1 paper requires these types to be trivially
copyable. They always have been in libstdc++, but add tests to check it.
libstdc++-v3/ChangeLog:
* testsuite/21_strings/basic_string_view/requirements/trivially_copyable.cc:
New test.
* testsuite/23_containers/span/trivially_copyable.cc: New test.
(cherry picked from commit 1f51e9af7b615838424214e6aaea0de793cb10fe)
Diff:
---
.../basic_string_view/requirements/trivially_copyable.cc | 11 +++++++++++
.../testsuite/23_containers/span/trivially_copyable.cc | 13 +++++++++++++
2 files changed, 24 insertions(+)
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/trivially_copyable.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/trivially_copyable.cc
new file mode 100644
index 00000000000..3f2589c61d8
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/trivially_copyable.cc
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++17 } }
+
+// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2251r1.pdf
+
+#include <string_view>
+
+static_assert( std::is_trivially_copyable_v<std::string_view> );
+static_assert( std::is_trivially_copyable_v<std::wstring_view> );
+
+struct traits : std::char_traits<char> { };
+static_assert( std::is_trivially_copyable_v<std::basic_string_view<char, traits>> );
diff --git a/libstdc++-v3/testsuite/23_containers/span/trivially_copyable.cc b/libstdc++-v3/testsuite/23_containers/span/trivially_copyable.cc
new file mode 100644
index 00000000000..e3748293555
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/span/trivially_copyable.cc
@@ -0,0 +1,13 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2251r1.pdf
+
+#include <span>
+
+static_assert( std::is_trivially_copyable_v<std::span<int>> );
+static_assert( std::is_trivially_copyable_v<std::span<int, 42>> );
+
+struct NonTrivial { NonTrivial(); NonTrivial(const NonTrivial&); };
+static_assert( std::is_trivially_copyable_v<std::span<NonTrivial>> );
+static_assert( std::is_trivially_copyable_v<std::span<NonTrivial, 99>> );
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-12 10:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 10:59 [gcc r11-9118] libstdc++: Ensure std::span and std::string_view are trivially copyable (P2251R1) 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).