From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 873B7384F011; Mon, 12 Jul 2021 17:36:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 873B7384F011 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-2257] libstdc++: Constrain std::as_writable_bytes [PR101411] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 3f2338b4706cdc53ab276b9a5fed7f6927404f07 X-Git-Newrev: 9d4393af9d2b37b78eb5b1f84f5d4da3a6f7fba6 Message-Id: <20210712173604.873B7384F011@sourceware.org> Date: Mon, 12 Jul 2021 17:36:04 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jul 2021 17:36:04 -0000 https://gcc.gnu.org/g:9d4393af9d2b37b78eb5b1f84f5d4da3a6f7fba6 commit r12-2257-g9d4393af9d2b37b78eb5b1f84f5d4da3a6f7fba6 Author: Jonathan Wakely 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 libstdc++-v3/ChangeLog: PR libstdc++/101411 * include/std/span (as_writable_bytes): Add requires-clause. * testsuite/23_containers/span/101411.cc: New test. 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 63f0a8f6279..21d8f6a43a6 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -425,6 +425,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + requires (!is_const_v<_Type>) inline span 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..05bdd3badbd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/span/101411.cc @@ -0,0 +1,15 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { xfail c++20 } } +#include + +// PR libstdc++/101411 + +void f(std::span s) +{ + std::as_writable_bytes(s); // { dg-error "no matching function" } +} + +void f1(std::span s) +{ + std::as_writable_bytes(s); // { dg-error "no matching function" } +}