public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Constrain std::as_writable_bytes [PR101411]
@ 2021-07-12 17:36 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-07-12 17:36 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 450 bytes --]

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.

Tested powerpc64le-linux. Committed to trunk.

I'll backport this too.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1663 bytes --]

commit 9d4393af9d2b37b78eb5b1f84f5d4da3a6f7fba6
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jul 12 16:09:34 2021

    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.

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<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..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 <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" }
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-12 17:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 17:36 [committed] libstdc++: Constrain std::as_writable_bytes [PR101411] Jonathan Wakely

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).