From: Jonathan Wakely Date: Mon, 12 Jul 2021 15:09:34 +0000 (+0100) Subject: libstdc++: Constrain std::as_writable_bytes [PR101411] X-Git-Tag: releases/gcc-11.2.0~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df115674b39d4004252b7d5e41d9751f2b77b0d8;p=thirdparty%2Fgcc.git 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. (cherry picked from commit 9d4393af9d2b37b78eb5b1f84f5d4da3a6f7fba6) --- diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index 09bdcd69afbc..b44e3b9e9c79 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 000000000000..05bdd3badbdb --- /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" } +}