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-9981] libstdc++: Constrain std::as_writable_bytes [PR101411] Date: Wed, 14 Jul 2021 16:04:54 +0000 (GMT) [thread overview] Message-ID: <20210714160454.4E97C385383B@sourceware.org> (raw) https://gcc.gnu.org/g:a34c0973c994d750fb1231da7af96038417b7fe3 commit r10-9981-ga34c0973c994d750fb1231da7af96038417b7fe3 Author: Jonathan Wakely <jwakely@redhat.com> Date: Mon Jul 12 16:09:34 2021 +0100 libstdc++: Constrain std::as_writable_bytes [PR101411] The std::as_writable_bytes function should be constrained to only accept writable spans. Currently it can be called but then gives an error in the function body. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/101411 * include/std/span (as_writable_bytes): Add requires-clause. * testsuite/23_containers/span/101411.cc: New test. (cherry picked from commit 9d4393af9d2b37b78eb5b1f84f5d4da3a6f7fba6) Diff: --- libstdc++-v3/include/std/span | 1 + libstdc++-v3/testsuite/23_containers/span/101411.cc | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index 1cdc0589ddb..9c9a4073507 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -430,6 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Type, size_t _Extent> + requires (!is_const_v<_Type>) inline span<byte, _Extent == dynamic_extent ? dynamic_extent : _Extent * sizeof(_Type)> diff --git a/libstdc++-v3/testsuite/23_containers/span/101411.cc b/libstdc++-v3/testsuite/23_containers/span/101411.cc new file mode 100644 index 00000000000..deae73689da --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/span/101411.cc @@ -0,0 +1,15 @@ +// { dg-options "-std=gnu++2a" } +// { dg-do compile { xfail c++2a } } +#include <span> + +// PR libstdc++/101411 + +void f(std::span<const int> s) +{ + std::as_writable_bytes(s); // { dg-error "unsatisfied constraints" } +} + +void f1(std::span<const int, 1> s) +{ + std::as_writable_bytes(s); // { dg-error "unsatisfied constraints" } +}
reply other threads:[~2021-07-14 16:04 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=20210714160454.4E97C385383B@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).