[gcc r15-11506] libstdc++: Fix openmode for ospanstream's spanbuf [PR127006]
Jonathan Wakely
redi@gcc.gnu.org
Tue Aug 25 10:19:20 GMT 2026
https://gcc.gnu.org/g:f680b40948a2f255f5882b07994ba92052c630a8
commit r15-11506-gf680b40948a2f255f5882b07994ba92052c630a8
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 7c2ef315e297..46c1adabce42 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