[gcc r16-9592] libstdc++: Fix openmode for ospanstream's spanbuf [PR127006]

Jonathan Wakely redi@gcc.gnu.org
Tue Aug 25 10:17:03 GMT 2026


https://gcc.gnu.org/g:70b2c1aa40cb026ac6711543716d095fc1e362eb

commit r16-9592-g70b2c1aa40cb026ac6711543716d095fc1e362eb
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Aug 24 11:21:49 2026 +0100

    libstdc++: Fix openmode for ospanstream's spanbuf [PR127006]
    
    The basic_ospanstream constructor is supposed to ensure that the
    basic_spanbuf is opened for output. I made a copy & paste error from the
    basic_ispanstream constructor.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/127006
            * include/std/spanstream (basic_ospanstream(span, openmode)):
            Add correct openmode value to parameter.
            * testsuite/27_io/spanstream/127006.cc: New test.
    
    (cherry picked from commit c8e065ed391115f763af09004f593a3db1fa5514)

Diff:
---
 libstdc++-v3/include/std/spanstream               |  2 +-
 libstdc++-v3/testsuite/27_io/spanstream/127006.cc | 30 +++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/spanstream b/libstdc++-v3/include/std/spanstream
index 815430927e3e..7cb8a23190bc 100644
--- a/libstdc++-v3/include/std/spanstream
+++ b/libstdc++-v3/include/std/spanstream
@@ -342,7 +342,7 @@ template<typename _CharT, typename _Traits>
     basic_ospanstream(std::span<_CharT> __s,
 		      ios_base::openmode __which = ios_base::out)
     : __ostream_type(std::__addressof(_M_sb)),
-      _M_sb(__s, __which | ios_base::in)
+      _M_sb(__s, __which | ios_base::out)
     { }
 
     basic_ospanstream(const basic_ospanstream&) = delete;
diff --git a/libstdc++-v3/testsuite/27_io/spanstream/127006.cc b/libstdc++-v3/testsuite/27_io/spanstream/127006.cc
new file mode 100644
index 000000000000..a15f6edb69ad
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/spanstream/127006.cc
@@ -0,0 +1,30 @@
+// { dg-do run { target c++23 } }
+
+#include <spanstream>
+#include <testsuite_hooks.h>
+
+void
+test_pr127006_out()
+{
+  // PR libstdc++/127006
+  char buf[3]{};
+  std::ospanstream s(buf, std::ios::openmode{});
+  VERIFY( s << 'x' );
+  VERIFY( buf[0] == 'x' );
+}
+
+void
+test_pr127006_in()
+{
+  char buf[3]{'x'};
+  std::ispanstream s(buf, std::ios::openmode{});
+  char x;
+  VERIFY( s >> x );
+  VERIFY( x == 'x' );
+}
+
+int main()
+{
+  test_pr127006_out();
+  test_pr127006_in();
+}


More information about the Libstdc++-cvs mailing list