public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10191] libstdc++: Ensure std::span and std::string_view are trivially copyable (P2251R1) Date: Tue, 12 Oct 2021 16:28:46 +0000 (GMT) [thread overview] Message-ID: <20211012162846.CDEEB385743D@sourceware.org> (raw) https://gcc.gnu.org/g:07e4cc8714b2b38e281cad01a69f6ec1db3e84c4 commit r10-10191-g07e4cc8714b2b38e281cad01a69f6ec1db3e84c4 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>> );
reply other threads:[~2021-10-12 16:28 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=20211012162846.CDEEB385743D@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@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: linkBe 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).