]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Constrain std::as_writable_bytes [PR101411]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 12 Jul 2021 15:09:34 +0000 (16:09 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 14 Jul 2021 14:59:49 +0000 (15:59 +0100)
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)

libstdc++-v3/include/std/span
libstdc++-v3/testsuite/23_containers/span/101411.cc [new file with mode: 0644]

index 09bdcd69afbc723a204684060b838c0a278ce30c..b44e3b9e9c799d9504855147d17f4e072b8b3ad1 100644 (file)
@@ -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)>
diff --git a/libstdc++-v3/testsuite/23_containers/span/101411.cc b/libstdc++-v3/testsuite/23_containers/span/101411.cc
new file mode 100644 (file)
index 0000000..05bdd3b
--- /dev/null
@@ -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" }
+}