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.
This commit is contained in:
parent
3f2338b470
commit
9d4393af9d
@ -425,6 +425,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)>
|
||||
|
15
libstdc++-v3/testsuite/23_containers/span/101411.cc
Normal file
15
libstdc++-v3/testsuite/23_containers/span/101411.cc
Normal file
@ -0,0 +1,15 @@
|
||||
// { dg-options "-std=gnu++20" }
|
||||
// { dg-do compile { xfail c++20 } }
|
||||
#include <span>
|
||||
|
||||
// PR libstdc++/101411
|
||||
|
||||
void f(std::span<const int> s)
|
||||
{
|
||||
std::as_writable_bytes(s); // { dg-error "no matching function" }
|
||||
}
|
||||
|
||||
void f1(std::span<const int, 1> s)
|
||||
{
|
||||
std::as_writable_bytes(s); // { dg-error "no matching function" }
|
||||
}
|
Loading…
Reference in New Issue
Block a user