[committed] libstdc++: Fix openmode for ospanstream's spanbuf [PR127006]
Jonathan Wakely
jwakely@redhat.com
Mon Aug 24 11:28:09 GMT 2026
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.
---
Tested x86_64-linux. Pushed to trunk. Backports to follow.
libstdc++-v3/include/std/spanstream | 2 +-
.../testsuite/27_io/spanstream/127006.cc | 30 +++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 libstdc++-v3/testsuite/27_io/spanstream/127006.cc
diff --git a/libstdc++-v3/include/std/spanstream b/libstdc++-v3/include/std/spanstream
index 6f1f681ae793..0cef65ae8880 100644
--- a/libstdc++-v3/include/std/spanstream
+++ b/libstdc++-v3/include/std/spanstream
@@ -343,7 +343,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();
+}
--
2.55.0
More information about the Libstdc++
mailing list