From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Ensure std::span and std::string_view are trivially copyable (P2251R1)
Date: Tue, 5 Oct 2021 16:48:22 +0100 [thread overview]
Message-ID: <YVxzxkSW5sypfTr5@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 369 bytes --]
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.
Tested x86_64-linux. Committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2182 bytes --]
commit 1f51e9af7b615838424214e6aaea0de793cb10fe
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Oct 5 16:38:42 2021
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.
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>> );
reply other threads:[~2021-10-05 15:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YVxzxkSW5sypfTr5@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).