[libcxx-commits] [libcxx] WIP - [libc++][spanstream] P0448R4: A `strstream` replacement using `span<charT>` as buffer (PR #83541)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 6 12:00:40 PST 2024


https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/83541

>From cd6abbc933fa4c815ba017e2e652281d847b0deb Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 27 Feb 2024 08:51:49 +0200
Subject: [PATCH 01/29] [libc++][spanstream] P0448R4: A `strstream` replacement
 using `span<charT>` as buffer

Implements: P0448R https://wg21.link/P0448R4
- https://eel.is/c++draft/span.streams
  - https://eel.is/c++draft/spanbuf
  - https://eel.is/c++draft/ispanstream
  - https://eel.is/c++draft/ospanstream
  - https://eel.is/c++draft/spanstream
---
 libcxx/docs/FeatureTestMacroTable.rst         |   2 +-
 libcxx/docs/ReleaseNotes/19.rst               |   1 +
 libcxx/docs/Status/Cxx23Papers.csv            |   2 +-
 libcxx/include/CMakeLists.txt                 |   1 +
 libcxx/include/__std_clang_module             |   3 +
 libcxx/include/module.modulemap               |   4 +
 libcxx/include/spanstream                     | 428 ++++++++++++++++++
 libcxx/include/version                        |   2 +-
 libcxx/modules/std.compat.cppm.in             |   3 -
 libcxx/modules/std.cppm.in                    |   6 +-
 .../ispanstream.general/lit.local.cfg         |   3 +
 .../nothing_to_do.pass.cpp                    |  15 +
 .../ispanstream/types.compile.pass.cpp        |  79 ++++
 .../ospanstream.general/lit.local.cfg         |   3 +
 .../nothing_to_do.pass.cpp                    |  15 +
 .../ospanstream/types.compile.pass.cpp        |  79 ++++
 .../spanbuf/spanbuf.cons/default.pass.cpp     |  45 ++
 .../spanbuf/spanbuf.general/lit.local.cfg     |   3 +
 .../spanbuf.general/nothing_to_do.pass.cpp    |  15 +
 .../spanbuf/types.compile.pass.cpp            |  79 ++++
 .../spanstream.general/lit.local.cfg          |   3 +
 .../spanstream.general/nothing_to_do.pass.cpp |  15 +
 .../spanstream/types.compile.pass.cpp         |  78 ++++
 .../spanstream.version.compile.pass.cpp       |  68 +++
 .../version.version.compile.pass.cpp          |  32 +-
 .../generate_feature_test_macro_components.py |   1 -
 libcxx/utils/libcxx/header_information.py     |   3 +-
 27 files changed, 955 insertions(+), 33 deletions(-)
 create mode 100644 libcxx/include/spanstream
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.general/lit.local.cfg
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.general/nothing_to_do.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.general/lit.local.cfg
 create mode 100644 libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.general/nothing_to_do.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.general/lit.local.cfg
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.general/nothing_to_do.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanstream/spanstream.general/lit.local.cfg
 create mode 100644 libcxx/test/std/input.output/span.streams/spanstream/spanstream.general/nothing_to_do.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
 create mode 100644 libcxx/test/std/language.support/support.limits/support.limits.general/spanstream.version.compile.pass.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index b213f430aa5922..c9ccdf7588498a 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -372,7 +372,7 @@ Status
     --------------------------------------------------- -----------------
     ``__cpp_lib_reference_from_temporary``              *unimplemented*
     --------------------------------------------------- -----------------
-    ``__cpp_lib_spanstream``                            *unimplemented*
+    ``__cpp_lib_spanstream``                            ``202106L``
     --------------------------------------------------- -----------------
     ``__cpp_lib_stacktrace``                            *unimplemented*
     --------------------------------------------------- -----------------
diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index 04f16610f8117e..373aeac26b280c 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -42,6 +42,7 @@ Implemented Papers
 - P2652R2 - Disallow User Specialization of ``allocator_traits``
 - P2819R2 - Add ``tuple`` protocol to ``complex``
 - P2495R3 - Interfacing ``stringstream``\s with ``string_view``
+- P0448R4 - A ``strstream`` replacement using ``span<charT>`` as buffer
 - P2302R4 - ``std::ranges::contains``
 - P1659R3 - ``std::ranges::starts_with`` and ``std::ranges::ends_with``
 
diff --git a/libcxx/docs/Status/Cxx23Papers.csv b/libcxx/docs/Status/Cxx23Papers.csv
index 56e1468b4ca1a3..576269c15ae6f1 100644
--- a/libcxx/docs/Status/Cxx23Papers.csv
+++ b/libcxx/docs/Status/Cxx23Papers.csv
@@ -12,7 +12,7 @@
 "`P2259R1 <https://wg21.link/P2259R1>`__","LWG","Repairing input range adaptors and counted_iterator","February 2021","","","|ranges|"
 "","","","","","",""
 "`P0401R6 <https://wg21.link/P0401R6>`__","LWG","Providing size feedback in the Allocator interface","June 2021","|Complete|","15.0"
-"`P0448R4 <https://wg21.link/P0448R4>`__","LWG","A strstream replacement using span<charT> as buffer","June 2021","",""
+"`P0448R4 <https://wg21.link/P0448R4>`__","LWG","A ``strstream`` replacement using ``span<charT>`` as buffer","June 2021","|Partial|","19.0"
 "`P1132R8 <https://wg21.link/P1132R8>`__","LWG","out_ptr - a scalable output pointer abstraction","June 2021","",""
 "`P1328R1 <https://wg21.link/P1328R1>`__","LWG","Making std::type_info::operator== constexpr","June 2021","|Complete|","17.0"
 "`P1425R4 <https://wg21.link/P1425R4>`__","LWG","Iterators pair constructors for stack and queue","June 2021","|Complete|","14.0","|ranges|"
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 3ea3360186dc56..b0caf97d0a72f0 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -987,6 +987,7 @@ set(files
   shared_mutex
   source_location
   span
+  spanstream
   sstream
   stack
   stdatomic.h
diff --git a/libcxx/include/__std_clang_module b/libcxx/include/__std_clang_module
index 18d6ce6b46c1f6..f7cefc697c316f 100644
--- a/libcxx/include/__std_clang_module
+++ b/libcxx/include/__std_clang_module
@@ -163,6 +163,9 @@
 #include <source_location>
 #include <span>
 #if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#  include <spanstream>
+#endif
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
 #  include <sstream>
 #endif
 #include <stack>
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index b247f97c1804d9..bcf3fe9d48500b 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -233,6 +233,10 @@ module std_span [system] {
   export std_version
   export std_private_span_span_fwd
 }
+module std_spanstream [system] {
+  header "spanstream"
+  export *
+}
 module std_sstream [system] {
   header "sstream"
   export *
diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
new file mode 100644
index 00000000000000..f25a04c2cb5254
--- /dev/null
+++ b/libcxx/include/spanstream
@@ -0,0 +1,428 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SPANSTREAM
+#define _LIBCPP_SPANSTREAM
+
+// clang-format off
+
+/*
+  Span-based streams [span.streams]
+
+  template<class charT, class traits = char_traits<charT>>
+    class basic_spanbuf;
+
+  template<class charT, class traits>
+    void swap(basic_spanbuf<charT, traits>& x, basic_spanbuf<charT, traits>& y);
+
+  using spanbuf = basic_spanbuf<char>;
+  using wspanbuf = basic_spanbuf<wchar_t>;
+
+  template<class charT, class traits = char_traits<charT>>
+    class basic_ispanstream;
+
+  template<class charT, class traits>
+    void swap(basic_ispanstream<charT, traits>& x, basic_ispanstream<charT, traits>& y);
+
+  using ispanstream = basic_ispanstream<char>;
+  using wispanstream = basic_ispanstream<wchar_t>;
+
+  template<class charT, class traits = char_traits<charT>>
+    class basic_ospanstream;
+
+  template<class charT, class traits>
+    void swap(basic_ospanstream<charT, traits>& x, basic_ospanstream<charT, traits>& y);
+
+  using ospanstream = basic_ospanstream<char>;
+  using wospanstream = basic_ospanstream<wchar_t>;
+
+  template<class charT, class traits = char_traits<charT>>
+    class basic_spanstream;
+
+  template<class charT, class traits>
+    void swap(basic_spanstream<charT, traits>& x, basic_spanstream<charT, traits>& y);
+
+  using spanstream = basic_spanstream<char>;
+  using wspanstream = basic_spanstream<wchar_t>;
+*/
+
+// clang-format on
+
+#include <__assert> // all public C++ headers provide the assertion handler
+#include <__availability>
+#include <__config>
+#include <__memory/addressof.h>
+#include <__ranges/concepts.h>
+#include <__utility/cmp.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include <__utility/swap.h>
+#include <iostream>
+#include <span>
+#include <streambuf>
+#include <version>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+// Class template basic_spanbuf [spanbuf]
+
+template <class _CharT, class _Traits = char_traits<_CharT>>
+class _LIBCPP_TEMPLATE_VIS basic_spanbuf : public basic_streambuf<_CharT, _Traits> {
+public:
+  using char_type   = _CharT;
+  using int_type    = typename _Traits::int_type;
+  using pos_type    = typename _Traits::pos_type;
+  using off_type    = typename _Traits::off_type;
+  using traits_type = _Traits;
+
+  // [spanbuf.cons], constructors
+
+  _LIBCPP_HIDE_FROM_ABI basic_spanbuf() : basic_spanbuf(ios_base::in | ios_base::out) {}
+
+  _LIBCPP_HIDE_FROM_ABI explicit basic_spanbuf(ios_base::openmode __which)
+      : basic_spanbuf(std::span<_CharT>(), __which) {}
+
+  _LIBCPP_HIDE_FROM_ABI explicit basic_spanbuf(std::span<_CharT> __s,
+                                               ios_base::openmode __which = ios_base::in | ios_base::out)
+      : basic_streambuf<_CharT, _Traits>{}, __mode_{__which}, __buf_{__s} {
+    this->span(__s);
+  }
+
+  basic_spanbuf(const basic_spanbuf&) = delete;
+  _LIBCPP_HIDE_FROM_ABI basic_spanbuf(basic_spanbuf&& __rhs)
+      : basic_streambuf<_CharT, _Traits>{std::move(__rhs)},
+        __mode_{std::move(__rhs.__mode_)},
+        __buf_{std::move(__rhs.__buf_)} {}
+
+  // [spanbuf.assign], assignment and swap
+
+  basic_spanbuf& operator=(const basic_spanbuf&) = delete;
+  _LIBCPP_HIDE_FROM_ABI basic_spanbuf& operator=(basic_spanbuf&& __rhs) {
+    basic_spanbuf __tmp{std::move(__rhs)};
+    this->swap(__tmp);
+    return *this;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI void swap(basic_spanbuf& __rhs) {
+    basic_streambuf<_CharT, _Traits>::swap(__rhs);
+    std::swap(__mode_, __rhs.__mode_);
+    std::swap(__buf_, __rhs.__buf_);
+  }
+
+  // [spanbuf.members], member functions
+
+  _LIBCPP_HIDE_FROM_ABI std::span<_CharT> span() const noexcept {
+    if (__mode_ & ios_base::out) {
+      return std::span<_CharT>(this->pbase(), this->pptr());
+    }
+    return __buf_;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI void span(std::span<_CharT> __s) noexcept {
+    __buf_ = __s;
+
+    if (__mode_ & ios_base::out) {
+      this->setp(__s.data(), __s.data() + __s.size());
+      if (__mode_ & ios_base::ate) {
+        this->pbump(__s.size());
+      }
+    }
+
+    if (__mode_ & ios_base::in) {
+      this->setg(__s.data(), __s.data(), __s.data() + __s.size());
+    }
+  }
+
+protected:
+  // [spanbuf.virtuals], overridden virtual functions
+
+  _LIBCPP_HIDE_FROM_ABI basic_streambuf<_CharT, _Traits>* setbuf(_CharT* __s, streamsize __n) override {
+    this->span(std::span<_CharT>(__s, __n));
+    return this;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI pos_type
+  seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) override {
+    const pos_type __error(off_type(-1));
+
+    if ((__which & ios_base::in) && (__which & ios_base::out) && (ios_base::cur == __way))
+      return __error;
+
+    off_type __baseoff = [this, __way, __which] {
+      switch (__way) {
+      case ios_base::beg:
+        return off_type(0);
+
+      case ios_base::cur:
+        if (__which & ios_base::out)
+          return off_type(this->pptr() - this->pbase());
+        return off_type(this->gptr() - this->eback());
+
+      case ios_base::end:
+        if ((__which & ios_base::out) && !(__which & ios_base::in))
+          return off_type(this->pptr() - this->pbase());
+        return off_type(__buf_.size());
+      }
+    }();
+
+    off_type __newoff;
+    if (__builtin_add_overflow(__baseoff, __off, &__newoff) || (__newoff < off_type(0)) ||
+        (std::cmp_greater(__newoff, __buf_.size())))
+      return __error;
+
+    if (__which & ios_base::in) {
+      if ((this->gptr() == nullptr) && (__newoff != off_type(0)))
+        return __error;
+      this->setg(this->eback(), this->eback() + __newoff, this->egptr());
+    }
+
+    if (__which & ios_base::out) {
+      if ((this->pptr() == nullptr) && (__newoff != off_type(0)))
+        return __error;
+      this->setp(this->pbase(), this->epptr());
+      this->pbump(__newoff);
+    }
+
+    return pos_type(__newoff);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI pos_type seekpos(pos_type __sp,
+                                         ios_base::openmode __which = ios_base::in | ios_base::out) override {
+    return seekoff(off_type(__sp), ios_base::beg, __which);
+  }
+
+private:
+  ios_base::openmode __mode_; // exposition only
+  std::span<_CharT> __buf_;   // exposition only
+};
+
+template <class _CharT, class _Traits>
+void swap(basic_spanbuf<_CharT, _Traits>& __x, basic_spanbuf<_CharT, _Traits>& __y) {
+  __x.swap(__y);
+}
+
+using spanbuf = basic_spanbuf<char>;
+#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+using wspanbuf = basic_spanbuf<wchar_t>;
+#  endif
+
+// Class template basic_ispanstream [ispanstream]
+
+template <class _CharT, class _Traits = char_traits<_CharT>>
+class basic_ispanstream : public basic_istream<_CharT, _Traits> {
+public:
+  using char_type   = _CharT;
+  using int_type    = typename _Traits::int_type;
+  using pos_type    = typename _Traits::pos_type;
+  using off_type    = typename _Traits::off_type;
+  using traits_type = _Traits;
+
+  // [ispanstream.cons], constructors
+
+  explicit basic_ispanstream(std::span<_CharT> __s, ios_base::openmode __which = ios_base::in)
+      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)),
+        __sb_(basic_spanbuf<_CharT, _Traits>(__s, __which | ios_base::in)) {}
+
+  basic_ispanstream(const basic_ispanstream&) = delete;
+
+  basic_ispanstream(basic_ispanstream&& __rhs)
+      : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
+    basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
+  }
+
+  template <ranges::borrowed_range _ROSeq>
+    requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
+  explicit basic_ispanstream(_ROSeq&& __s) : basic_istream<_CharT, _Traits>(std::addressof(__sb_)) {
+    std::span<const _CharT> __sp(std::forward<_ROSeq>(__s));
+    this->span(std::span<_CharT>(std::span<_CharT>(const_cast<_CharT*>(__sp.data()), __sp.size())));
+  }
+
+  basic_ispanstream& operator=(const basic_ispanstream&) = delete;
+
+  basic_ispanstream& operator=(basic_ispanstream&& __rhs) {
+    basic_ispanstream __tmp{std::move(__rhs)};
+    this->swap(__tmp);
+    return *this;
+  }
+
+  // [ispanstream.swap], swap
+
+  void swap(basic_ispanstream& __rhs) {
+    basic_istream<_CharT, _Traits>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+  }
+
+  // [ispanstream.members], member functions
+
+  basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept {
+    return const_cast<basic_spanbuf<_CharT, _Traits>*>(std::addressof(__sb_));
+  }
+
+  std::span<const _CharT> span() const noexcept { return rdbuf()->span(); }
+
+  void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
+
+  template <ranges::borrowed_range _ROSeq>
+    requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
+  void span(_ROSeq&& __s) noexcept {
+    std::span<const _CharT> __sp(std::forward<_ROSeq>(__s));
+    this->span(std::span<_CharT>(const_cast<_CharT*>(__sp.data()), __sp.size()));
+  }
+
+private:
+  basic_spanbuf<_CharT, _Traits> __sb_; // exposition only
+};
+
+template <class _CharT, class _Traits>
+void swap(basic_ispanstream<_CharT, _Traits>& __x, basic_ispanstream<_CharT, _Traits>& __y) {
+  __x.swap(__y);
+}
+
+using ispanstream = basic_ispanstream<char>;
+#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+using wispanstream = basic_ispanstream<wchar_t>;
+#  endif
+
+// Class template basic_ospanstream [ospanstream]
+
+template <class _CharT, class _Traits = char_traits<_CharT>>
+class basic_ospanstream : public basic_ostream<_CharT, _Traits> {
+public:
+  using char_type   = _CharT;
+  using int_type    = typename _Traits::int_type;
+  using pos_type    = typename _Traits::pos_type;
+  using off_type    = typename _Traits::off_type;
+  using traits_type = _Traits;
+
+  // [ospanstream.cons], constructors
+
+  explicit basic_ospanstream(std::span<_CharT> __s, ios_base::openmode __which = ios_base::out)
+      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)),
+        __sb_(basic_spanbuf<_CharT, _Traits>(__s, __which | ios_base::out)) {}
+
+  basic_ospanstream(const basic_ospanstream&) = delete;
+
+  basic_ospanstream(basic_ospanstream&& __rhs) : basic_ospanstream(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
+    basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
+  }
+
+  basic_ospanstream& operator=(const basic_ospanstream&) = delete;
+
+  basic_ospanstream& operator=(basic_ospanstream&& __rhs) {
+    basic_ospanstream __tmp{std::move(__rhs)};
+    this->swap(__tmp);
+    return *this;
+  }
+
+  // [ospanstream.swap], swap
+
+  void swap(basic_ospanstream& __rhs) {
+    basic_ostream<_CharT, _Traits>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+  }
+
+  // [ospanstream.members], member functions
+
+  basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept { return __sb_; }
+
+  std::span<_CharT> span() const noexcept { return __sb_.rdbuf()->span(); }
+
+  void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
+
+private:
+  basic_spanbuf<_CharT, _Traits> __sb_; // exposition only
+};
+
+template <class _CharT, class _Traits>
+void swap(basic_ospanstream<_CharT, _Traits>& __x, basic_ospanstream<_CharT, _Traits>& __y) {
+  __x.swap(__y);
+}
+
+using ospanstream = basic_ospanstream<char>;
+#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+using wospanstream = basic_ospanstream<wchar_t>;
+#  endif
+
+template <class _CharT, class _Traits = char_traits<_CharT>>
+class basic_spanstream : public basic_iostream<_CharT, _Traits> {
+public:
+  using char_type   = _CharT;
+  using int_type    = typename _Traits::int_type;
+  using pos_type    = typename _Traits::pos_type;
+  using off_type    = typename _Traits::off_type;
+  using traits_type = _Traits;
+
+  // [spanstream.cons], constructors
+
+  explicit basic_spanstream(std::span<_CharT> __s, ios_base::openmode __which = ios_base::out | ios_base::in)
+      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(basic_spanbuf<_CharT, _Traits>(__s, __which)) {}
+
+  basic_spanstream(const basic_spanstream&) = delete;
+
+  basic_spanstream(basic_spanstream&& __rhs) : basic_spanstream(std::move(__rhs)), __sb_(__rhs.__sb_) {
+    basic_iostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
+  }
+
+  basic_spanstream& operator=(const basic_spanstream&) = delete;
+
+  basic_spanstream& operator=(basic_spanstream&& __rhs) {
+    basic_spanstream __tmp{std::move(__rhs)};
+    this->swap(__tmp);
+    return *this;
+  }
+
+  // [spanstream.swap], swap
+
+  void swap(basic_spanstream& __rhs) {
+    basic_iostream<_CharT, _Traits>::swap(__rhs);
+    __sb_.swap(__rhs.__sb_);
+  }
+
+  // [spanstream.members], members
+
+  basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept { return __sb_; }
+
+  std::span<_CharT> span() const noexcept { return rdbuf()->span(); }
+
+  void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
+
+private:
+  basic_spanbuf<_CharT, _Traits> __sb_; // exposition only
+};
+
+template <class _CharT, class _Traits>
+void swap(basic_spanstream<_CharT, _Traits>& __x, basic_spanstream<_CharT, _Traits>& __y) {
+  __x.swap(__y);
+}
+
+using spanstream = basic_spanstream<char>;
+#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+using wspanstream = basic_spanstream<wchar_t>;
+#  endif
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#if _LIBCPP_STD_VER <= 20 && !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
+#  include <type_traits>
+#endif
+
+#endif // _LIBCPP_SPANSTREAM
diff --git a/libcxx/include/version b/libcxx/include/version
index 3bd296e34aa4e3..d5bda9cca32501 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -473,7 +473,7 @@ __cpp_lib_within_lifetime                               202306L <type_traits>
 # define __cpp_lib_ranges_to_container                  202202L
 // # define __cpp_lib_ranges_zip                           202110L
 // # define __cpp_lib_reference_from_temporary             202202L
-// # define __cpp_lib_spanstream                           202106L
+# define __cpp_lib_spanstream                           202106L
 // # define __cpp_lib_stacktrace                           202011L
 # define __cpp_lib_stdatomic_h                          202011L
 # define __cpp_lib_string_contains                      202011L
diff --git a/libcxx/modules/std.compat.cppm.in b/libcxx/modules/std.compat.cppm.in
index b44dbab25c74b4..80e6b254905ec1 100644
--- a/libcxx/modules/std.compat.cppm.in
+++ b/libcxx/modules/std.compat.cppm.in
@@ -75,9 +75,6 @@ module;
 #  if __has_include(<rcu>)
 #    error "please update the header information for <rcu> in headers_not_available in utils/libcxx/header_information.py"
 #  endif // __has_include(<rcu>)
-#  if __has_include(<spanstream>)
-#    error "please update the header information for <spanstream> in headers_not_available in utils/libcxx/header_information.py"
-#  endif // __has_include(<spanstream>)
 #  if __has_include(<stacktrace>)
 #    error "please update the header information for <stacktrace> in headers_not_available in utils/libcxx/header_information.py"
 #  endif // __has_include(<stacktrace>)
diff --git a/libcxx/modules/std.cppm.in b/libcxx/modules/std.cppm.in
index b8d89130aae989..d53d666c8de5c4 100644
--- a/libcxx/modules/std.cppm.in
+++ b/libcxx/modules/std.cppm.in
@@ -133,6 +133,9 @@ module;
 #include <source_location>
 #include <span>
 #if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#  include <spanstream>
+#endif
+#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
 #  include <sstream>
 #endif
 #include <stack>
@@ -197,9 +200,6 @@ module;
 #  if __has_include(<rcu>)
 #    error "please update the header information for <rcu> in headers_not_available in utils/libcxx/header_information.py"
 #  endif // __has_include(<rcu>)
-#  if __has_include(<spanstream>)
-#    error "please update the header information for <spanstream> in headers_not_available in utils/libcxx/header_information.py"
-#  endif // __has_include(<spanstream>)
 #  if __has_include(<stacktrace>)
 #    error "please update the header information for <stacktrace> in headers_not_available in utils/libcxx/header_information.py"
 #  endif // __has_include(<stacktrace>)
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.general/lit.local.cfg b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.general/lit.local.cfg
new file mode 100644
index 00000000000000..2cb10010c45072
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.general/lit.local.cfg
@@ -0,0 +1,3 @@
+# All non-trivial uses of iostreams require localization support
+if "no-localization" in config.available_features:
+    config.unsupported = True
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.general/nothing_to_do.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.general/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000000..4a307014fa0f72
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.general/nothing_to_do.pass.cpp
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+// [ispanstream.general]
+
+int main(int, char**) { return 0; }
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
new file mode 100644
index 00000000000000..773efffd61a39c
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ispanstream
+//     : public basic_istream<charT, traits> {
+//   public:
+//     using char_type   = charT;
+//     using int_type    = typename traits::int_type;
+//     using pos_type    = typename traits::pos_type;
+//     using off_type    = typename traits::off_type;
+//     using traits_type = traits;
+
+//   using ispanstream = basic_ispanstream<char>;
+//   using wispanstream = basic_ispanstream<wchar_t>;
+
+#include <spanstream>
+#include <string>
+#include <type_traits>
+
+#include "test_macros.h"
+
+// Types
+
+static_assert(std::is_base_of_v<std::basic_istream<char>, std::ispanstream>);
+static_assert(std::is_same_v<std::ispanstream::char_type, char>);
+static_assert(std::is_same_v<std::ispanstream::int_type, std::char_traits<char>::int_type>);
+static_assert(std::is_same_v<std::ispanstream::pos_type, std::char_traits<char>::pos_type>);
+static_assert(std::is_same_v<std::ispanstream::off_type, std::char_traits<char>::off_type>);
+static_assert(std::is_same_v<std::ispanstream::traits_type, std::char_traits<char>>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::is_base_of_v<std::basic_istream<wchar_t>, std::wispanstream>);
+static_assert(std::is_same_v<std::wispanstream::char_type, wchar_t>);
+static_assert(std::is_same_v<std::wispanstream::int_type, std::char_traits<wchar_t>::int_type>);
+static_assert(std::is_same_v<std::wispanstream::pos_type, std::char_traits<wchar_t>::pos_type>);
+static_assert(std::is_same_v<std::wispanstream::off_type, std::char_traits<wchar_t>::off_type>);
+static_assert(std::is_same_v<std::wispanstream::traits_type, std::char_traits<wchar_t>>);
+#endif
+
+// Copy properties
+
+static_assert(!std::is_copy_constructible_v<std::ispanstream>);
+static_assert(!std::is_copy_assignable_v<std::ispanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible_v<std::wispanstream>);
+static_assert(!std::is_copy_assignable_v<std::wispanstream>);
+#endif
+
+// Move properties
+
+static_assert(!std::is_copy_constructible_v<std::ispanstream>);
+static_assert(!std::is_copy_assignable_v<std::ispanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible_v<std::wispanstream>);
+static_assert(!std::is_copy_assignable_v<std::wispanstream>);
+#endif
+
+// Move properties
+
+static_assert(std::is_move_constructible_v<std::ispanstream>);
+static_assert(std::is_move_assignable_v<std::ispanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::is_move_constructible_v<std::wispanstream>);
+static_assert(std::is_move_assignable_v<std::wispanstream>);
+#endif
+
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.general/lit.local.cfg b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.general/lit.local.cfg
new file mode 100644
index 00000000000000..2cb10010c45072
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.general/lit.local.cfg
@@ -0,0 +1,3 @@
+# All non-trivial uses of iostreams require localization support
+if "no-localization" in config.available_features:
+    config.unsupported = True
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.general/nothing_to_do.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.general/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000000..6f9497040a8977
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.general/nothing_to_do.pass.cpp
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+// [ospanstream.general]
+
+int main(int, char**) { return 0; }
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
new file mode 100644
index 00000000000000..ab0cac07168407
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ospanstream
+//     : public basic_ostream<charT, traits> {
+//   public:
+//     using char_type   = charT;
+//     using int_type    = typename traits::int_type;
+//     using pos_type    = typename traits::pos_type;
+//     using off_type    = typename traits::off_type;
+//     using traits_type = traits;
+
+//   using ospanstream = basic_ospanstream<char>;
+//   using wospanstream = basic_ospanstream<wchar_t>;
+
+#include <spanstream>
+#include <string>
+#include <type_traits>
+
+#include "test_macros.h"
+
+// Types
+
+static_assert(std::is_base_of_v<std::basic_ostream<char>, std::ospanstream>);
+static_assert(std::is_same_v<std::ospanstream::char_type, char>);
+static_assert(std::is_same_v<std::ospanstream::int_type, std::char_traits<char>::int_type>);
+static_assert(std::is_same_v<std::ospanstream::pos_type, std::char_traits<char>::pos_type>);
+static_assert(std::is_same_v<std::ospanstream::off_type, std::char_traits<char>::off_type>);
+static_assert(std::is_same_v<std::ospanstream::traits_type, std::char_traits<char>>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::is_base_of_v<std::basic_ostream<wchar_t>, std::wospanstream>);
+static_assert(std::is_same_v<std::wospanstream::char_type, wchar_t>);
+static_assert(std::is_same_v<std::wospanstream::int_type, std::char_traits<wchar_t>::int_type>);
+static_assert(std::is_same_v<std::wospanstream::pos_type, std::char_traits<wchar_t>::pos_type>);
+static_assert(std::is_same_v<std::wospanstream::off_type, std::char_traits<wchar_t>::off_type>);
+static_assert(std::is_same_v<std::wospanstream::traits_type, std::char_traits<wchar_t>>);
+#endif
+
+// Copy properties
+
+static_assert(!std::is_copy_constructible_v<std::ospanstream>);
+static_assert(!std::is_copy_assignable_v<std::ospanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible_v<std::wospanstream>);
+static_assert(!std::is_copy_assignable_v<std::wospanstream>);
+#endif
+
+// Move properties
+
+static_assert(!std::is_copy_constructible_v<std::ospanstream>);
+static_assert(!std::is_copy_assignable_v<std::ospanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible_v<std::wospanstream>);
+static_assert(!std::is_copy_assignable_v<std::wospanstream>);
+#endif
+
+// Move properties
+
+static_assert(std::is_move_constructible_v<std::ospanstream>);
+static_assert(std::is_move_assignable_v<std::ospanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::is_move_constructible_v<std::wospanstream>);
+static_assert(std::is_move_assignable_v<std::wospanstream>);
+#endif
+
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
new file mode 100644
index 00000000000000..4675c0e5fc2990
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//     basic_spanbuf();
+
+#include <cassert>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_macros.h"
+
+template <typename CharT, typename Traits = std::char_traits<CharT>>
+void test() {
+  using SpanBuf = std::basic_spanbuf<CharT, Traits>;
+
+  static_assert(std::default_initializable<SpanBuf>);
+
+  SpanBuf spBuf;
+  assert(spBuf.span().empty());
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.general/lit.local.cfg b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.general/lit.local.cfg
new file mode 100644
index 00000000000000..2cb10010c45072
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.general/lit.local.cfg
@@ -0,0 +1,3 @@
+# All non-trivial uses of iostreams require localization support
+if "no-localization" in config.available_features:
+    config.unsupported = True
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.general/nothing_to_do.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.general/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000000..fc746f4af7c762
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.general/nothing_to_do.pass.cpp
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+// [spanbuf.general]
+
+int main(int, char**) { return 0; }
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
new file mode 100644
index 00000000000000..4585147ea8d2e7
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_streambuf<charT, traits> {
+//   public:
+//     using char_type   = charT;
+//     using int_type    = typename traits::int_type;
+//     using pos_type    = typename traits::pos_type;
+//     using off_type    = typename traits::off_type;
+//     using traits_type = traits;
+
+//   using spanbuf = basic_spanbufchar>;
+//   using wspanbuf = basic_spanbuf<wchar_t>;
+
+#include <spanstream>
+#include <string>
+#include <type_traits>
+
+#include "test_macros.h"
+
+// Types
+
+static_assert(std::is_base_of_v<std::basic_streambuf<char>, std::spanbuf>);
+static_assert(std::is_same_v<std::spanbuf::char_type, char>);
+static_assert(std::is_same_v<std::spanbuf::int_type, std::char_traits<char>::int_type>);
+static_assert(std::is_same_v<std::spanbuf::pos_type, std::char_traits<char>::pos_type>);
+static_assert(std::is_same_v<std::spanbuf::off_type, std::char_traits<char>::off_type>);
+static_assert(std::is_same_v<std::spanbuf::traits_type, std::char_traits<char>>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::is_base_of_v<std::basic_streambuf<wchar_t>, std::wspanbuf>);
+static_assert(std::is_same_v<std::wspanbuf::char_type, wchar_t>);
+static_assert(std::is_same_v<std::wspanbuf::int_type, std::char_traits<wchar_t>::int_type>);
+static_assert(std::is_same_v<std::wspanbuf::pos_type, std::char_traits<wchar_t>::pos_type>);
+static_assert(std::is_same_v<std::wspanbuf::off_type, std::char_traits<wchar_t>::off_type>);
+static_assert(std::is_same_v<std::wspanbuf::traits_type, std::char_traits<wchar_t>>);
+#endif
+
+// Copy properties
+
+static_assert(!std::is_copy_constructible_v<std::spanbuf>);
+static_assert(!std::is_copy_assignable_v<std::spanbuf>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible_v<std::wspanbuf>);
+static_assert(!std::is_copy_assignable_v<std::wspanbuf>);
+#endif
+
+// Move properties
+
+static_assert(!std::is_copy_constructible_v<std::spanbuf>);
+static_assert(!std::is_copy_assignable_v<std::spanbuf>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible_v<std::wspanbuf>);
+static_assert(!std::is_copy_assignable_v<std::wspanbuf>);
+#endif
+
+// Move properties
+
+static_assert(std::is_move_constructible_v<std::spanbuf>);
+static_assert(std::is_move_assignable_v<std::spanbuf>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::is_move_constructible_v<std::wspanbuf>);
+static_assert(std::is_move_assignable_v<std::wspanbuf>);
+#endif
+
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.general/lit.local.cfg b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.general/lit.local.cfg
new file mode 100644
index 00000000000000..2cb10010c45072
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.general/lit.local.cfg
@@ -0,0 +1,3 @@
+# All non-trivial uses of iostreams require localization support
+if "no-localization" in config.available_features:
+    config.unsupported = True
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.general/nothing_to_do.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.general/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000000..8677bb6d0906d3
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.general/nothing_to_do.pass.cpp
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+// [spanstream.general]
+
+int main(int, char**) { return 0; }
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
new file mode 100644
index 00000000000000..4e90f259ccf488
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanstream
+//     : public basic_iostream<charT, traits> {
+//   public:
+//     using char_type   = charT;
+//     using int_type    = typename traits::int_type;
+//     using pos_type    = typename traits::pos_type;
+//     using off_type    = typename traits::off_type;
+//     using traits_type = traits;
+
+//   using spanstream = basic_spanstream<char>;
+//   using wspanstream = basic_spanstream<wchar_t>;
+
+#include <spanstream>
+#include <string>
+#include <type_traits>
+
+#include "test_macros.h"
+
+// Types
+
+static_assert(std::is_base_of_v<std::basic_iostream<char>, std::spanstream>);
+static_assert(std::is_same_v<std::spanstream::char_type, char>);
+static_assert(std::is_same_v<std::spanstream::int_type, std::char_traits<char>::int_type>);
+static_assert(std::is_same_v<std::spanstream::pos_type, std::char_traits<char>::pos_type>);
+static_assert(std::is_same_v<std::spanstream::off_type, std::char_traits<char>::off_type>);
+static_assert(std::is_same_v<std::spanstream::traits_type, std::char_traits<char>>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::is_base_of_v<std::basic_iostream<wchar_t>, std::wspanstream>);
+static_assert(std::is_same_v<std::wspanstream::char_type, wchar_t>);
+static_assert(std::is_same_v<std::wspanstream::int_type, std::char_traits<wchar_t>::int_type>);
+static_assert(std::is_same_v<std::wspanstream::pos_type, std::char_traits<wchar_t>::pos_type>);
+static_assert(std::is_same_v<std::wspanstream::off_type, std::char_traits<wchar_t>::off_type>);
+static_assert(std::is_same_v<std::wspanstream::traits_type, std::char_traits<wchar_t>>);
+#endif
+
+// Copy properties
+
+static_assert(!std::is_copy_constructible_v<std::spanstream>);
+static_assert(!std::is_copy_assignable_v<std::spanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible_v<std::wspanstream>);
+static_assert(!std::is_copy_assignable_v<std::wspanstream>);
+#endif
+
+// Move properties
+
+static_assert(!std::is_copy_constructible_v<std::spanstream>);
+static_assert(!std::is_copy_assignable_v<std::spanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::is_copy_constructible_v<std::wspanstream>);
+static_assert(!std::is_copy_assignable_v<std::wspanstream>);
+#endif
+
+// Move properties
+
+static_assert(std::is_move_constructible_v<std::spanstream>);
+static_assert(std::is_move_assignable_v<std::spanstream>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::is_move_constructible_v<std::wspanstream>);
+static_assert(std::is_move_assignable_v<std::wspanstream>);
+#endif
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/spanstream.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/spanstream.version.compile.pass.cpp
new file mode 100644
index 00000000000000..8719352d4367e3
--- /dev/null
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/spanstream.version.compile.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// WARNING: This test was generated by generate_feature_test_macro_components.py
+// and should not be edited manually.
+//
+// clang-format off
+
+// <spanstream>
+
+// Test the feature test macros defined by <spanstream>
+
+/*  Constant                Value
+    __cpp_lib_spanstream    202106L [C++23]
+*/
+
+#include <spanstream>
+#include "test_macros.h"
+
+#if TEST_STD_VER < 14
+
+# ifdef __cpp_lib_spanstream
+#   error "__cpp_lib_spanstream should not be defined before c++23"
+# endif
+
+#elif TEST_STD_VER == 14
+
+# ifdef __cpp_lib_spanstream
+#   error "__cpp_lib_spanstream should not be defined before c++23"
+# endif
+
+#elif TEST_STD_VER == 17
+
+# ifdef __cpp_lib_spanstream
+#   error "__cpp_lib_spanstream should not be defined before c++23"
+# endif
+
+#elif TEST_STD_VER == 20
+
+# ifdef __cpp_lib_spanstream
+#   error "__cpp_lib_spanstream should not be defined before c++23"
+# endif
+
+#elif TEST_STD_VER == 23
+
+# ifndef __cpp_lib_spanstream
+#   error "__cpp_lib_spanstream should be defined in c++23"
+# endif
+# if __cpp_lib_spanstream != 202106L
+#   error "__cpp_lib_spanstream should have the value 202106L in c++23"
+# endif
+
+#elif TEST_STD_VER > 23
+
+# ifndef __cpp_lib_spanstream
+#   error "__cpp_lib_spanstream should be defined in c++26"
+# endif
+# if __cpp_lib_spanstream != 202106L
+#   error "__cpp_lib_spanstream should have the value 202106L in c++26"
+# endif
+
+#endif // TEST_STD_VER > 23
+
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index 5501587915ffa0..a09396245d3ef4 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -5626,17 +5626,11 @@
 #   error "__cpp_lib_span_initializer_list should not be defined before c++26"
 # endif
 
-# if !defined(_LIBCPP_VERSION)
-#   ifndef __cpp_lib_spanstream
-#     error "__cpp_lib_spanstream should be defined in c++23"
-#   endif
-#   if __cpp_lib_spanstream != 202106L
-#     error "__cpp_lib_spanstream should have the value 202106L in c++23"
-#   endif
-# else // _LIBCPP_VERSION
-#   ifdef __cpp_lib_spanstream
-#     error "__cpp_lib_spanstream should not be defined because it is unimplemented in libc++!"
-#   endif
+# ifndef __cpp_lib_spanstream
+#   error "__cpp_lib_spanstream should be defined in c++23"
+# endif
+# if __cpp_lib_spanstream != 202106L
+#   error "__cpp_lib_spanstream should have the value 202106L in c++23"
 # endif
 
 # ifndef __cpp_lib_ssize
@@ -7374,17 +7368,11 @@
 #   error "__cpp_lib_span_initializer_list should have the value 202311L in c++26"
 # endif
 
-# if !defined(_LIBCPP_VERSION)
-#   ifndef __cpp_lib_spanstream
-#     error "__cpp_lib_spanstream should be defined in c++26"
-#   endif
-#   if __cpp_lib_spanstream != 202106L
-#     error "__cpp_lib_spanstream should have the value 202106L in c++26"
-#   endif
-# else // _LIBCPP_VERSION
-#   ifdef __cpp_lib_spanstream
-#     error "__cpp_lib_spanstream should not be defined because it is unimplemented in libc++!"
-#   endif
+# ifndef __cpp_lib_spanstream
+#   error "__cpp_lib_spanstream should be defined in c++26"
+# endif
+# if __cpp_lib_spanstream != 202106L
+#   error "__cpp_lib_spanstream should have the value 202106L in c++26"
 # endif
 
 # ifndef __cpp_lib_ssize
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index c55f5c7d19004a..69bca109fca195 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -1105,7 +1105,6 @@ def add_version_header(tc):
             "name": "__cpp_lib_spanstream",
             "values": {"c++23": 202106},
             "headers": ["spanstream"],
-            "unimplemented": True,
         },
         {
             "name": "__cpp_lib_ssize",
diff --git a/libcxx/utils/libcxx/header_information.py b/libcxx/utils/libcxx/header_information.py
index bccae353b0c6bd..62ae499be91421 100644
--- a/libcxx/utils/libcxx/header_information.py
+++ b/libcxx/utils/libcxx/header_information.py
@@ -26,6 +26,7 @@
     "locale": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
     "ostream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
     "regex": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
+    "spanstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
     "sstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
     "streambuf": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
     "strstream": "!defined(_LIBCPP_HAS_NO_LOCALIZATION)",
@@ -76,6 +77,7 @@
     "regex": "// UNSUPPORTED: no-localization",
     "semaphore": "// UNSUPPORTED: no-threads, c++03, c++11, c++14, c++17",
     "shared_mutex": "// UNSUPPORTED: no-threads, c++03, c++11",
+    "spanstream": "// UNSUPPORTED: no-localization",
     "sstream": "// UNSUPPORTED: no-localization",
     "stdatomic.h": "// UNSUPPORTED: no-threads, c++03, c++11, c++14, c++17, c++20",
     "stop_token": "// UNSUPPORTED: no-threads, c++03, c++11, c++14, c++17",
@@ -145,7 +147,6 @@
     "hazard_pointer",
     "linalg",
     "rcu",
-    "spanstream",
     "stacktrace",
     "stdfloat",
     "text_encoding",

>From 7e828d2099989334c420735cf6eac1313ea53204 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 28 Feb 2024 18:30:36 +0200
Subject: [PATCH 02/29] Added forward declarations to `<iosfwd>`

---
 libcxx/include/CMakeLists.txt     |  1 +
 libcxx/include/__fwd/spanstream.h | 48 +++++++++++++++++++++++++++++++
 libcxx/include/iosfwd             | 20 +++++++++++++
 libcxx/include/libcxx.imp         |  1 +
 libcxx/include/module.modulemap   | 15 +++++-----
 libcxx/include/spanstream         | 15 +++++-----
 6 files changed, 86 insertions(+), 14 deletions(-)
 create mode 100644 libcxx/include/__fwd/spanstream.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index b0caf97d0a72f0..4499a6d5176048 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -439,6 +439,7 @@ set(files
   __fwd/ostream.h
   __fwd/pair.h
   __fwd/span.h
+  __fwd/spanstream.h
   __fwd/sstream.h
   __fwd/streambuf.h
   __fwd/string.h
diff --git a/libcxx/include/__fwd/spanstream.h b/libcxx/include/__fwd/spanstream.h
new file mode 100644
index 00000000000000..2afeaaecf7fb4d
--- /dev/null
+++ b/libcxx/include/__fwd/spanstream.h
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___FWD_SPANSTREAM_H
+#define _LIBCPP___FWD_SPANSTREAM_H
+
+#include <__config>
+#include <__fwd/string.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+template <class _CharT, class traits = char_traits<_CharT>>
+class _LIBCPP_TEMPLATE_VIS basic_spanbuf;
+template <class _CharT, class traits = char_traits<_CharT>>
+class _LIBCPP_TEMPLATE_VIS basic_ispanstream;
+template <class _CharT, class traits = char_traits<_CharT>>
+class _LIBCPP_TEMPLATE_VIS basic_ospanstream;
+template <class _CharT, class traits = char_traits<_CharT>>
+class _LIBCPP_TEMPLATE_VIS basic_spanstream;
+
+using spanbuf     = basic_spanbuf<char>;
+using ispanstream = basic_ispanstream<char>;
+using ospanstream = basic_ospanstream<char>;
+using spanstream  = basic_spanstream<char>;
+
+#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+using wspanbuf     = basic_spanbuf<wchar_t>;
+using wispanstream = basic_ispanstream<wchar_t>;
+using wospanstream = basic_ospanstream<wchar_t>;
+using wspanstream  = basic_spanstream<wchar_t>;
+#  endif
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___FWD_SPANSTREAM_H
diff --git a/libcxx/include/iosfwd b/libcxx/include/iosfwd
index f1c2cbd9669679..c9d459592e2879 100644
--- a/libcxx/include/iosfwd
+++ b/libcxx/include/iosfwd
@@ -42,6 +42,15 @@ template <class charT, class traits = char_traits<charT>, class Allocator = allo
 template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
     class basic_stringstream;
 
+  template<class charT, class traits = char_traits<charT>>
+    class basic_spanbuf;                                                             // Since C++23
+  template<class charT, class traits = char_traits<charT>>
+    class basic_ispanstream;                                                         // Since C++23
+  template<class charT, class traits = char_traits<charT>>
+    class basic_ospanstream;                                                         // Since C++23
+  template<class charT, class traits = char_traits<charT>>
+    class basic_spanstream;                                                          // Since C++23
+
 template <class charT, class traits = char_traits<charT> > class basic_filebuf;
 template <class charT, class traits = char_traits<charT> > class basic_ifstream;
 template <class charT, class traits = char_traits<charT> > class basic_ofstream;
@@ -63,6 +72,11 @@ typedef basic_istringstream<char>    istringstream;
 typedef basic_ostringstream<char>    ostringstream;
 typedef basic_stringstream<char>     stringstream;
 
+using spanbuf     = basic_spanbuf<char>;                                             // Since C++23
+using ispanstream = basic_ispanstream<char>;                                         // Since C++23
+using ospanstream = basic_ospanstream<char>;                                         // Since C++23
+using spanstream  = basic_spanstream<char>;                                          // Since C++23
+
 typedef basic_filebuf<char>          filebuf;
 typedef basic_ifstream<char>         ifstream;
 typedef basic_ofstream<char>         ofstream;
@@ -78,6 +92,11 @@ typedef basic_istringstream<wchar_t> wistringstream;
 typedef basic_ostringstream<wchar_t> wostringstream;
 typedef basic_stringstream<wchar_t>  wstringstream;
 
+using wspanbuf     = basic_spanbuf<wchar_t>;                                         // Since C++23
+using wispanstream = basic_ispanstream<wchar_t>;                                     // Since C++23
+using wospanstream = basic_ospanstream<wchar_t>;                                     // Since C++23
+using wspanstream  = basic_spanstream<wchar_t>;                                      // Since C++23
+
 typedef basic_filebuf<wchar_t>       wfilebuf;
 typedef basic_ifstream<wchar_t>      wifstream;
 typedef basic_ofstream<wchar_t>      wofstream;
@@ -111,6 +130,7 @@ using wosyncstream = basic_osyncstream<wchar_t>;  // C++20
 #include <__fwd/ios.h>
 #include <__fwd/istream.h>
 #include <__fwd/ostream.h>
+#include <__fwd/spanstream.h>
 #include <__fwd/sstream.h>
 #include <__fwd/streambuf.h>
 #include <__fwd/string.h>
diff --git a/libcxx/include/libcxx.imp b/libcxx/include/libcxx.imp
index cdbb0a63fc0eae..5818c4916751f9 100644
--- a/libcxx/include/libcxx.imp
+++ b/libcxx/include/libcxx.imp
@@ -434,6 +434,7 @@
   { include: [ "<__fwd/ostream.h>", "private", "<iosfwd>", "public" ] },
   { include: [ "<__fwd/pair.h>", "private", "<utility>", "public" ] },
   { include: [ "<__fwd/span.h>", "private", "<span>", "public" ] },
+  { include: [ "<__fwd/spanstream.h>", "private", "<spanstream>", "public" ] },
   { include: [ "<__fwd/sstream.h>", "private", "<iosfwd>", "public" ] },
   { include: [ "<__fwd/streambuf.h>", "private", "<iosfwd>", "public" ] },
   { include: [ "<__fwd/string.h>", "private", "<string>", "public" ] },
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index bcf3fe9d48500b..e5db0f86d80df7 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1392,14 +1392,15 @@ module std_private_functional_unary_function             [system] { header "__fu
 module std_private_functional_unary_negate               [system] { header "__functional/unary_negate.h" }
 module std_private_functional_weak_result_type           [system] { header "__functional/weak_result_type.h" }
 
-module std_private_ios_fpos [system] { header "__ios/fpos.h" }
+module std_private_ios_fpos                         [system] { header "__ios/fpos.h" }
 
-module std_private_iosfwd_fstream_fwd   [system] { header "__fwd/fstream.h" }
-module std_private_iosfwd_ios_fwd       [system] { header "__fwd/ios.h" }
-module std_private_iosfwd_istream_fwd   [system] { header "__fwd/istream.h" }
-module std_private_iosfwd_ostream_fwd   [system] { header "__fwd/ostream.h" }
-module std_private_iosfwd_sstream_fwd   [system] { header "__fwd/sstream.h" }
-module std_private_iosfwd_streambuf_fwd [system] { header "__fwd/streambuf.h" }
+module std_private_iosfwd_fstream_fwd               [system] { header "__fwd/fstream.h" }
+module std_private_iosfwd_ios_fwd                   [system] { header "__fwd/ios.h" }
+module std_private_iosfwd_istream_fwd               [system] { header "__fwd/istream.h" }
+module std_private_iosfwd_ostream_fwd               [system] { header "__fwd/ostream.h" }
+module std_private_iosfwd_spanstream_fwd            [system] { header "__fwd/spanstream.h" }
+module std_private_iosfwd_sstream_fwd               [system] { header "__fwd/sstream.h" }
+module std_private_iosfwd_streambuf_fwd             [system] { header "__fwd/streambuf.h" }
 
 module std_private_iterator_access                  [system] { header "__iterator/access.h" }
 module std_private_iterator_advance                 [system] { header "__iterator/advance.h" }
diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index f25a04c2cb5254..ffaba85ef252c0 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -57,6 +57,7 @@
 #include <__assert> // all public C++ headers provide the assertion handler
 #include <__availability>
 #include <__config>
+#include <__fwd/spanstream.h>
 #include <__memory/addressof.h>
 #include <__ranges/concepts.h>
 #include <__utility/cmp.h>
@@ -81,7 +82,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // Class template basic_spanbuf [spanbuf]
 
-template <class _CharT, class _Traits = char_traits<_CharT>>
+template <class _CharT, class _Traits>
 class _LIBCPP_TEMPLATE_VIS basic_spanbuf : public basic_streambuf<_CharT, _Traits> {
 public:
   using char_type   = _CharT;
@@ -223,8 +224,8 @@ using wspanbuf = basic_spanbuf<wchar_t>;
 
 // Class template basic_ispanstream [ispanstream]
 
-template <class _CharT, class _Traits = char_traits<_CharT>>
-class basic_ispanstream : public basic_istream<_CharT, _Traits> {
+template <class _CharT, class _Traits>
+class _LIBCPP_TEMPLATE_VIS basic_ispanstream : public basic_istream<_CharT, _Traits> {
 public:
   using char_type   = _CharT;
   using int_type    = typename _Traits::int_type;
@@ -300,8 +301,8 @@ using wispanstream = basic_ispanstream<wchar_t>;
 
 // Class template basic_ospanstream [ospanstream]
 
-template <class _CharT, class _Traits = char_traits<_CharT>>
-class basic_ospanstream : public basic_ostream<_CharT, _Traits> {
+template <class _CharT, class _Traits>
+class _LIBCPP_TEMPLATE_VIS basic_ospanstream : public basic_ostream<_CharT, _Traits> {
 public:
   using char_type   = _CharT;
   using int_type    = typename _Traits::int_type;
@@ -358,8 +359,8 @@ using ospanstream = basic_ospanstream<char>;
 using wospanstream = basic_ospanstream<wchar_t>;
 #  endif
 
-template <class _CharT, class _Traits = char_traits<_CharT>>
-class basic_spanstream : public basic_iostream<_CharT, _Traits> {
+template <class _CharT, class _Traits>
+class _LIBCPP_TEMPLATE_VIS basic_spanstream : public basic_iostream<_CharT, _Traits> {
 public:
   using char_type   = _CharT;
   using int_type    = typename _Traits::int_type;

>From 7c9eab0f1ec8b9acb40d21514385dcd24f81e616 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 28 Feb 2024 19:01:08 +0200
Subject: [PATCH 03/29] Tests: updated `types.compile.pass`

---
 .../ispanstream/types.compile.pass.cpp        | 67 +++++++++----------
 .../ospanstream/types.compile.pass.cpp        | 67 +++++++++----------
 .../spanbuf/types.compile.pass.cpp            | 67 +++++++++----------
 .../spanstream/types.compile.pass.cpp         | 66 +++++++++---------
 4 files changed, 132 insertions(+), 135 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
index 773efffd61a39c..9615d270116ee4 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
@@ -27,53 +27,52 @@
 #include <string>
 #include <type_traits>
 
+#include "constexpr_char_traits.h"
 #include "test_macros.h"
 
-// Types
+template <typename CharT, typename Traits = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ispanstream<CharT, Traits>;
 
-static_assert(std::is_base_of_v<std::basic_istream<char>, std::ispanstream>);
-static_assert(std::is_same_v<std::ispanstream::char_type, char>);
-static_assert(std::is_same_v<std::ispanstream::int_type, std::char_traits<char>::int_type>);
-static_assert(std::is_same_v<std::ispanstream::pos_type, std::char_traits<char>::pos_type>);
-static_assert(std::is_same_v<std::ispanstream::off_type, std::char_traits<char>::off_type>);
-static_assert(std::is_same_v<std::ispanstream::traits_type, std::char_traits<char>>);
+  // Types
 
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::is_base_of_v<std::basic_istream<wchar_t>, std::wispanstream>);
-static_assert(std::is_same_v<std::wispanstream::char_type, wchar_t>);
-static_assert(std::is_same_v<std::wispanstream::int_type, std::char_traits<wchar_t>::int_type>);
-static_assert(std::is_same_v<std::wispanstream::pos_type, std::char_traits<wchar_t>::pos_type>);
-static_assert(std::is_same_v<std::wispanstream::off_type, std::char_traits<wchar_t>::off_type>);
-static_assert(std::is_same_v<std::wispanstream::traits_type, std::char_traits<wchar_t>>);
-#endif
+  static_assert(std::is_base_of_v<std::basic_istream<CharT, Traits>, SpStream>);
+  static_assert(std::is_same_v<typename SpStream::char_type, CharT>);
+  static_assert(std::is_same_v<typename SpStream::int_type, typename Traits::int_type>);
+  static_assert(std::is_same_v<typename SpStream::pos_type, typename Traits::pos_type>);
+  static_assert(std::is_same_v<typename SpStream::off_type, typename Traits::off_type>);
+  static_assert(std::is_same_v<typename SpStream::traits_type, Traits>);
 
-// Copy properties
+  // Copy properties
 
-static_assert(!std::is_copy_constructible_v<std::ispanstream>);
-static_assert(!std::is_copy_assignable_v<std::ispanstream>);
+  static_assert(!std::is_copy_constructible_v<SpStream>);
+  static_assert(!std::is_copy_assignable_v<SpStream>);
 
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!std::is_copy_constructible_v<std::wispanstream>);
-static_assert(!std::is_copy_assignable_v<std::wispanstream>);
-#endif
+  // Move properties
 
-// Move properties
+  static_assert(!std::is_copy_constructible_v<SpStream>);
+  static_assert(!std::is_copy_assignable_v<SpStream>);
 
-static_assert(!std::is_copy_constructible_v<std::ispanstream>);
-static_assert(!std::is_copy_assignable_v<std::ispanstream>);
+  // Move properties
 
+  static_assert(std::is_move_constructible_v<SpStream>);
+  static_assert(std::is_move_assignable_v<SpStream>);
+}
+
+void test() {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!std::is_copy_constructible_v<std::wispanstream>);
-static_assert(!std::is_copy_assignable_v<std::wispanstream>);
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
 #endif
+}
 
-// Move properties
-
-static_assert(std::is_move_constructible_v<std::ispanstream>);
-static_assert(std::is_move_assignable_v<std::ispanstream>);
+// Aliases
 
+static_assert(std::is_base_of_v<std::basic_istream<char>, std::ispanstream>);
+static_assert(std::is_same_v<std::basic_ispanstream<char>, std::ispanstream>);
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::is_move_constructible_v<std::wispanstream>);
-static_assert(std::is_move_assignable_v<std::wispanstream>);
+static_assert(std::is_base_of_v<std::basic_istream<wchar_t>, std::wispanstream>);
+static_assert(std::is_same_v<std::basic_ispanstream<wchar_t>, std::wispanstream>);
 #endif
-
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
index ab0cac07168407..e5a9e574eb39f7 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
@@ -27,53 +27,52 @@
 #include <string>
 #include <type_traits>
 
+#include "constexpr_char_traits.h"
 #include "test_macros.h"
 
-// Types
+template <typename CharT, typename Traits = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ospanstream<CharT, Traits>;
 
-static_assert(std::is_base_of_v<std::basic_ostream<char>, std::ospanstream>);
-static_assert(std::is_same_v<std::ospanstream::char_type, char>);
-static_assert(std::is_same_v<std::ospanstream::int_type, std::char_traits<char>::int_type>);
-static_assert(std::is_same_v<std::ospanstream::pos_type, std::char_traits<char>::pos_type>);
-static_assert(std::is_same_v<std::ospanstream::off_type, std::char_traits<char>::off_type>);
-static_assert(std::is_same_v<std::ospanstream::traits_type, std::char_traits<char>>);
+  // Types
 
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::is_base_of_v<std::basic_ostream<wchar_t>, std::wospanstream>);
-static_assert(std::is_same_v<std::wospanstream::char_type, wchar_t>);
-static_assert(std::is_same_v<std::wospanstream::int_type, std::char_traits<wchar_t>::int_type>);
-static_assert(std::is_same_v<std::wospanstream::pos_type, std::char_traits<wchar_t>::pos_type>);
-static_assert(std::is_same_v<std::wospanstream::off_type, std::char_traits<wchar_t>::off_type>);
-static_assert(std::is_same_v<std::wospanstream::traits_type, std::char_traits<wchar_t>>);
-#endif
+  static_assert(std::is_base_of_v<std::basic_ostream<CharT, Traits>, SpStream>);
+  static_assert(std::is_same_v<typename SpStream::char_type, CharT>);
+  static_assert(std::is_same_v<typename SpStream::int_type, typename Traits::int_type>);
+  static_assert(std::is_same_v<typename SpStream::pos_type, typename Traits::pos_type>);
+  static_assert(std::is_same_v<typename SpStream::off_type, typename Traits::off_type>);
+  static_assert(std::is_same_v<typename SpStream::traits_type, Traits>);
 
-// Copy properties
+  // Copy properties
 
-static_assert(!std::is_copy_constructible_v<std::ospanstream>);
-static_assert(!std::is_copy_assignable_v<std::ospanstream>);
+  static_assert(!std::is_copy_constructible_v<SpStream>);
+  static_assert(!std::is_copy_assignable_v<SpStream>);
 
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!std::is_copy_constructible_v<std::wospanstream>);
-static_assert(!std::is_copy_assignable_v<std::wospanstream>);
-#endif
+  // Move properties
 
-// Move properties
+  static_assert(!std::is_copy_constructible_v<SpStream>);
+  static_assert(!std::is_copy_assignable_v<SpStream>);
 
-static_assert(!std::is_copy_constructible_v<std::ospanstream>);
-static_assert(!std::is_copy_assignable_v<std::ospanstream>);
+  // Move properties
 
+  static_assert(std::is_move_constructible_v<SpStream>);
+  static_assert(std::is_move_assignable_v<SpStream>);
+}
+
+void test() {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!std::is_copy_constructible_v<std::wospanstream>);
-static_assert(!std::is_copy_assignable_v<std::wospanstream>);
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
 #endif
+}
 
-// Move properties
-
-static_assert(std::is_move_constructible_v<std::ospanstream>);
-static_assert(std::is_move_assignable_v<std::ospanstream>);
+// Aliases
 
+static_assert(std::is_base_of_v<std::basic_ostream<char>, std::ospanstream>);
+static_assert(std::is_same_v<std::basic_ospanstream<char>, std::ospanstream>);
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::is_move_constructible_v<std::wospanstream>);
-static_assert(std::is_move_assignable_v<std::wospanstream>);
+static_assert(std::is_base_of_v<std::basic_ostream<wchar_t>, std::wospanstream>);
+static_assert(std::is_same_v<std::basic_ospanstream<wchar_t>, std::wospanstream>);
 #endif
-
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
index 4585147ea8d2e7..a8cc07ed524ea8 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
@@ -27,53 +27,52 @@
 #include <string>
 #include <type_traits>
 
+#include "constexpr_char_traits.h"
 #include "test_macros.h"
 
-// Types
+template <typename CharT, typename Traits = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, Traits>;
 
-static_assert(std::is_base_of_v<std::basic_streambuf<char>, std::spanbuf>);
-static_assert(std::is_same_v<std::spanbuf::char_type, char>);
-static_assert(std::is_same_v<std::spanbuf::int_type, std::char_traits<char>::int_type>);
-static_assert(std::is_same_v<std::spanbuf::pos_type, std::char_traits<char>::pos_type>);
-static_assert(std::is_same_v<std::spanbuf::off_type, std::char_traits<char>::off_type>);
-static_assert(std::is_same_v<std::spanbuf::traits_type, std::char_traits<char>>);
+  // Types
 
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::is_base_of_v<std::basic_streambuf<wchar_t>, std::wspanbuf>);
-static_assert(std::is_same_v<std::wspanbuf::char_type, wchar_t>);
-static_assert(std::is_same_v<std::wspanbuf::int_type, std::char_traits<wchar_t>::int_type>);
-static_assert(std::is_same_v<std::wspanbuf::pos_type, std::char_traits<wchar_t>::pos_type>);
-static_assert(std::is_same_v<std::wspanbuf::off_type, std::char_traits<wchar_t>::off_type>);
-static_assert(std::is_same_v<std::wspanbuf::traits_type, std::char_traits<wchar_t>>);
-#endif
+  static_assert(std::is_base_of_v<std::basic_streambuf<CharT, Traits>, SpBuf>);
+  static_assert(std::is_same_v<typename SpBuf::char_type, CharT>);
+  static_assert(std::is_same_v<typename SpBuf::int_type, typename Traits::int_type>);
+  static_assert(std::is_same_v<typename SpBuf::pos_type, typename Traits::pos_type>);
+  static_assert(std::is_same_v<typename SpBuf::off_type, typename Traits::off_type>);
+  static_assert(std::is_same_v<typename SpBuf::traits_type, Traits>);
 
-// Copy properties
+  // Copy properties
 
-static_assert(!std::is_copy_constructible_v<std::spanbuf>);
-static_assert(!std::is_copy_assignable_v<std::spanbuf>);
+  static_assert(!std::is_copy_constructible_v<SpBuf>);
+  static_assert(!std::is_copy_assignable_v<SpBuf>);
 
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!std::is_copy_constructible_v<std::wspanbuf>);
-static_assert(!std::is_copy_assignable_v<std::wspanbuf>);
-#endif
+  // Move properties
 
-// Move properties
+  static_assert(!std::is_copy_constructible_v<SpBuf>);
+  static_assert(!std::is_copy_assignable_v<SpBuf>);
 
-static_assert(!std::is_copy_constructible_v<std::spanbuf>);
-static_assert(!std::is_copy_assignable_v<std::spanbuf>);
+  // Move properties
 
+  static_assert(std::is_move_constructible_v<SpBuf>);
+  static_assert(std::is_move_assignable_v<SpBuf>);
+}
+
+void test() {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!std::is_copy_constructible_v<std::wspanbuf>);
-static_assert(!std::is_copy_assignable_v<std::wspanbuf>);
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
 #endif
+}
 
-// Move properties
-
-static_assert(std::is_move_constructible_v<std::spanbuf>);
-static_assert(std::is_move_assignable_v<std::spanbuf>);
+// Aliases
 
+static_assert(std::is_base_of_v<std::basic_streambuf<char>, std::spanbuf>);
+static_assert(std::is_same_v<std::basic_spanbuf<char>, std::spanbuf>);
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::is_move_constructible_v<std::wspanbuf>);
-static_assert(std::is_move_assignable_v<std::wspanbuf>);
+static_assert(std::is_base_of_v<std::basic_streambuf<wchar_t>, std::wspanbuf>);
+static_assert(std::is_same_v<std::basic_spanbuf<wchar_t>, std::wspanbuf>);
 #endif
-
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
index 4e90f259ccf488..5714834be2ce11 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
@@ -27,52 +27,52 @@
 #include <string>
 #include <type_traits>
 
+#include "constexpr_char_traits.h"
 #include "test_macros.h"
 
-// Types
+template <typename CharT, typename Traits = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_spanstream<CharT, Traits>;
 
-static_assert(std::is_base_of_v<std::basic_iostream<char>, std::spanstream>);
-static_assert(std::is_same_v<std::spanstream::char_type, char>);
-static_assert(std::is_same_v<std::spanstream::int_type, std::char_traits<char>::int_type>);
-static_assert(std::is_same_v<std::spanstream::pos_type, std::char_traits<char>::pos_type>);
-static_assert(std::is_same_v<std::spanstream::off_type, std::char_traits<char>::off_type>);
-static_assert(std::is_same_v<std::spanstream::traits_type, std::char_traits<char>>);
+  // Types
 
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::is_base_of_v<std::basic_iostream<wchar_t>, std::wspanstream>);
-static_assert(std::is_same_v<std::wspanstream::char_type, wchar_t>);
-static_assert(std::is_same_v<std::wspanstream::int_type, std::char_traits<wchar_t>::int_type>);
-static_assert(std::is_same_v<std::wspanstream::pos_type, std::char_traits<wchar_t>::pos_type>);
-static_assert(std::is_same_v<std::wspanstream::off_type, std::char_traits<wchar_t>::off_type>);
-static_assert(std::is_same_v<std::wspanstream::traits_type, std::char_traits<wchar_t>>);
-#endif
+  static_assert(std::is_base_of_v<std::basic_iostream<CharT, Traits>, SpStream>);
+  static_assert(std::is_same_v<typename SpStream::char_type, CharT>);
+  static_assert(std::is_same_v<typename SpStream::int_type, typename Traits::int_type>);
+  static_assert(std::is_same_v<typename SpStream::pos_type, typename Traits::pos_type>);
+  static_assert(std::is_same_v<typename SpStream::off_type, typename Traits::off_type>);
+  static_assert(std::is_same_v<typename SpStream::traits_type, Traits>);
 
-// Copy properties
+  // Copy properties
 
-static_assert(!std::is_copy_constructible_v<std::spanstream>);
-static_assert(!std::is_copy_assignable_v<std::spanstream>);
+  static_assert(!std::is_copy_constructible_v<SpStream>);
+  static_assert(!std::is_copy_assignable_v<SpStream>);
 
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!std::is_copy_constructible_v<std::wspanstream>);
-static_assert(!std::is_copy_assignable_v<std::wspanstream>);
-#endif
+  // Move properties
+
+  static_assert(!std::is_copy_constructible_v<SpStream>);
+  static_assert(!std::is_copy_assignable_v<SpStream>);
 
-// Move properties
+  // Move properties
 
-static_assert(!std::is_copy_constructible_v<std::spanstream>);
-static_assert(!std::is_copy_assignable_v<std::spanstream>);
+  static_assert(std::is_move_constructible_v<SpStream>);
+  static_assert(std::is_move_assignable_v<SpStream>);
+}
 
+void test() {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(!std::is_copy_constructible_v<std::wspanstream>);
-static_assert(!std::is_copy_assignable_v<std::wspanstream>);
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
 #endif
+}
 
-// Move properties
-
-static_assert(std::is_move_constructible_v<std::spanstream>);
-static_assert(std::is_move_assignable_v<std::spanstream>);
+// Aliases
 
+static_assert(std::is_base_of_v<std::basic_iostream<char>, std::spanstream>);
+static_assert(std::is_same_v<std::basic_spanstream<char>, std::spanstream>);
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::is_move_constructible_v<std::wspanstream>);
-static_assert(std::is_move_assignable_v<std::wspanstream>);
+static_assert(std::is_base_of_v<std::basic_iostream<wchar_t>, std::wspanstream>);
+static_assert(std::is_same_v<std::basic_spanstream<wchar_t>, std::wspanstream>);
 #endif

>From 26077c41bc6be0053f2a96214509422835d07780 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 28 Feb 2024 19:38:58 +0200
Subject: [PATCH 04/29] Implementation: added `_LIBCPP_HIDE_FROM_ABI`

---
 libcxx/include/__fwd/spanstream.h |  8 ++--
 libcxx/include/spanstream         | 74 +++++++++++++++++--------------
 2 files changed, 44 insertions(+), 38 deletions(-)

diff --git a/libcxx/include/__fwd/spanstream.h b/libcxx/include/__fwd/spanstream.h
index 2afeaaecf7fb4d..f5ff2ad2c9cfc6 100644
--- a/libcxx/include/__fwd/spanstream.h
+++ b/libcxx/include/__fwd/spanstream.h
@@ -20,13 +20,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER >= 23
 
-template <class _CharT, class traits = char_traits<_CharT>>
+template <class _CharT, class _Traits = char_traits<_CharT>>
 class _LIBCPP_TEMPLATE_VIS basic_spanbuf;
-template <class _CharT, class traits = char_traits<_CharT>>
+template <class _CharT, class _Traits = char_traits<_CharT>>
 class _LIBCPP_TEMPLATE_VIS basic_ispanstream;
-template <class _CharT, class traits = char_traits<_CharT>>
+template <class _CharT, class _Traits = char_traits<_CharT>>
 class _LIBCPP_TEMPLATE_VIS basic_ospanstream;
-template <class _CharT, class traits = char_traits<_CharT>>
+template <class _CharT, class _Traits = char_traits<_CharT>>
 class _LIBCPP_TEMPLATE_VIS basic_spanstream;
 
 using spanbuf     = basic_spanbuf<char>;
diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index ffaba85ef252c0..16bbf04d81c559 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -105,6 +105,7 @@ public:
   }
 
   basic_spanbuf(const basic_spanbuf&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI basic_spanbuf(basic_spanbuf&& __rhs)
       : basic_streambuf<_CharT, _Traits>{std::move(__rhs)},
         __mode_{std::move(__rhs.__mode_)},
@@ -113,6 +114,7 @@ public:
   // [spanbuf.assign], assignment and swap
 
   basic_spanbuf& operator=(const basic_spanbuf&) = delete;
+
   _LIBCPP_HIDE_FROM_ABI basic_spanbuf& operator=(basic_spanbuf&& __rhs) {
     basic_spanbuf __tmp{std::move(__rhs)};
     this->swap(__tmp);
@@ -213,13 +215,13 @@ private:
 };
 
 template <class _CharT, class _Traits>
-void swap(basic_spanbuf<_CharT, _Traits>& __x, basic_spanbuf<_CharT, _Traits>& __y) {
+_LIBCPP_HIDE_FROM_ABI void swap(basic_spanbuf<_CharT, _Traits>& __x, basic_spanbuf<_CharT, _Traits>& __y) {
   __x.swap(__y);
 }
 
-using spanbuf = basic_spanbuf<char>;
+using std::spanbuf;
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
-using wspanbuf = basic_spanbuf<wchar_t>;
+using std::wspanbuf;
 #  endif
 
 // Class template basic_ispanstream [ispanstream]
@@ -235,27 +237,28 @@ public:
 
   // [ispanstream.cons], constructors
 
-  explicit basic_ispanstream(std::span<_CharT> __s, ios_base::openmode __which = ios_base::in)
+  _LIBCPP_HIDE_FROM_ABI explicit basic_ispanstream(std::span<_CharT> __s, ios_base::openmode __which = ios_base::in)
       : basic_istream<_CharT, _Traits>(std::addressof(__sb_)),
         __sb_(basic_spanbuf<_CharT, _Traits>(__s, __which | ios_base::in)) {}
 
   basic_ispanstream(const basic_ispanstream&) = delete;
 
-  basic_ispanstream(basic_ispanstream&& __rhs)
+  _LIBCPP_HIDE_FROM_ABI basic_ispanstream(basic_ispanstream&& __rhs)
       : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 
   template <ranges::borrowed_range _ROSeq>
     requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
-  explicit basic_ispanstream(_ROSeq&& __s) : basic_istream<_CharT, _Traits>(std::addressof(__sb_)) {
+  _LIBCPP_HIDE_FROM_ABI explicit basic_ispanstream(_ROSeq&& __s)
+      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)) {
     std::span<const _CharT> __sp(std::forward<_ROSeq>(__s));
     this->span(std::span<_CharT>(std::span<_CharT>(const_cast<_CharT*>(__sp.data()), __sp.size())));
   }
 
   basic_ispanstream& operator=(const basic_ispanstream&) = delete;
 
-  basic_ispanstream& operator=(basic_ispanstream&& __rhs) {
+  _LIBCPP_HIDE_FROM_ABI basic_ispanstream& operator=(basic_ispanstream&& __rhs) {
     basic_ispanstream __tmp{std::move(__rhs)};
     this->swap(__tmp);
     return *this;
@@ -263,24 +266,24 @@ public:
 
   // [ispanstream.swap], swap
 
-  void swap(basic_ispanstream& __rhs) {
+  _LIBCPP_HIDE_FROM_ABI void swap(basic_ispanstream& __rhs) {
     basic_istream<_CharT, _Traits>::swap(__rhs);
     __sb_.swap(__rhs.__sb_);
   }
 
   // [ispanstream.members], member functions
 
-  basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept {
+  _LIBCPP_HIDE_FROM_ABI basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept {
     return const_cast<basic_spanbuf<_CharT, _Traits>*>(std::addressof(__sb_));
   }
 
-  std::span<const _CharT> span() const noexcept { return rdbuf()->span(); }
+  _LIBCPP_HIDE_FROM_ABI std::span<const _CharT> span() const noexcept { return rdbuf()->span(); }
 
-  void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
+  _LIBCPP_HIDE_FROM_ABI void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
 
   template <ranges::borrowed_range _ROSeq>
     requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
-  void span(_ROSeq&& __s) noexcept {
+  _LIBCPP_HIDE_FROM_ABI void span(_ROSeq&& __s) noexcept {
     std::span<const _CharT> __sp(std::forward<_ROSeq>(__s));
     this->span(std::span<_CharT>(const_cast<_CharT*>(__sp.data()), __sp.size()));
   }
@@ -290,13 +293,13 @@ private:
 };
 
 template <class _CharT, class _Traits>
-void swap(basic_ispanstream<_CharT, _Traits>& __x, basic_ispanstream<_CharT, _Traits>& __y) {
+_LIBCPP_HIDE_FROM_ABI void swap(basic_ispanstream<_CharT, _Traits>& __x, basic_ispanstream<_CharT, _Traits>& __y) {
   __x.swap(__y);
 }
 
-using ispanstream = basic_ispanstream<char>;
+using std::ispanstream;
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
-using wispanstream = basic_ispanstream<wchar_t>;
+using std::wispanstream;
 #  endif
 
 // Class template basic_ospanstream [ospanstream]
@@ -312,19 +315,20 @@ public:
 
   // [ospanstream.cons], constructors
 
-  explicit basic_ospanstream(std::span<_CharT> __s, ios_base::openmode __which = ios_base::out)
+  _LIBCPP_HIDE_FROM_ABI explicit basic_ospanstream(std::span<_CharT> __s, ios_base::openmode __which = ios_base::out)
       : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)),
         __sb_(basic_spanbuf<_CharT, _Traits>(__s, __which | ios_base::out)) {}
 
   basic_ospanstream(const basic_ospanstream&) = delete;
 
-  basic_ospanstream(basic_ospanstream&& __rhs) : basic_ospanstream(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
+  _LIBCPP_HIDE_FROM_ABI basic_ospanstream(basic_ospanstream&& __rhs)
+      : basic_ospanstream(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 
   basic_ospanstream& operator=(const basic_ospanstream&) = delete;
 
-  basic_ospanstream& operator=(basic_ospanstream&& __rhs) {
+  _LIBCPP_HIDE_FROM_ABI basic_ospanstream& operator=(basic_ospanstream&& __rhs) {
     basic_ospanstream __tmp{std::move(__rhs)};
     this->swap(__tmp);
     return *this;
@@ -332,31 +336,31 @@ public:
 
   // [ospanstream.swap], swap
 
-  void swap(basic_ospanstream& __rhs) {
+  _LIBCPP_HIDE_FROM_ABI void swap(basic_ospanstream& __rhs) {
     basic_ostream<_CharT, _Traits>::swap(__rhs);
     __sb_.swap(__rhs.__sb_);
   }
 
   // [ospanstream.members], member functions
 
-  basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept { return __sb_; }
+  _LIBCPP_HIDE_FROM_ABI basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept { return __sb_; }
 
-  std::span<_CharT> span() const noexcept { return __sb_.rdbuf()->span(); }
+  _LIBCPP_HIDE_FROM_ABI std::span<_CharT> span() const noexcept { return __sb_.rdbuf()->span(); }
 
-  void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
+  _LIBCPP_HIDE_FROM_ABI void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
 
 private:
   basic_spanbuf<_CharT, _Traits> __sb_; // exposition only
 };
 
 template <class _CharT, class _Traits>
-void swap(basic_ospanstream<_CharT, _Traits>& __x, basic_ospanstream<_CharT, _Traits>& __y) {
+_LIBCPP_HIDE_FROM_ABI void swap(basic_ospanstream<_CharT, _Traits>& __x, basic_ospanstream<_CharT, _Traits>& __y) {
   __x.swap(__y);
 }
 
-using ospanstream = basic_ospanstream<char>;
+using std::ospanstream;
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
-using wospanstream = basic_ospanstream<wchar_t>;
+using std::wospanstream;
 #  endif
 
 template <class _CharT, class _Traits>
@@ -370,18 +374,20 @@ public:
 
   // [spanstream.cons], constructors
 
-  explicit basic_spanstream(std::span<_CharT> __s, ios_base::openmode __which = ios_base::out | ios_base::in)
+  _LIBCPP_HIDE_FROM_ABI explicit basic_spanstream(std::span<_CharT> __s,
+                                                  ios_base::openmode __which = ios_base::out | ios_base::in)
       : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(basic_spanbuf<_CharT, _Traits>(__s, __which)) {}
 
   basic_spanstream(const basic_spanstream&) = delete;
 
-  basic_spanstream(basic_spanstream&& __rhs) : basic_spanstream(std::move(__rhs)), __sb_(__rhs.__sb_) {
+  _LIBCPP_HIDE_FROM_ABI basic_spanstream(basic_spanstream&& __rhs)
+      : basic_spanstream(std::move(__rhs)), __sb_(__rhs.__sb_) {
     basic_iostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 
   basic_spanstream& operator=(const basic_spanstream&) = delete;
 
-  basic_spanstream& operator=(basic_spanstream&& __rhs) {
+  _LIBCPP_HIDE_FROM_ABI basic_spanstream& operator=(basic_spanstream&& __rhs) {
     basic_spanstream __tmp{std::move(__rhs)};
     this->swap(__tmp);
     return *this;
@@ -396,24 +402,24 @@ public:
 
   // [spanstream.members], members
 
-  basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept { return __sb_; }
+  _LIBCPP_HIDE_FROM_ABI basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept { return __sb_; }
 
-  std::span<_CharT> span() const noexcept { return rdbuf()->span(); }
+  _LIBCPP_HIDE_FROM_ABI std::span<_CharT> span() const noexcept { return rdbuf()->span(); }
 
-  void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
+  _LIBCPP_HIDE_FROM_ABI void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
 
 private:
   basic_spanbuf<_CharT, _Traits> __sb_; // exposition only
 };
 
 template <class _CharT, class _Traits>
-void swap(basic_spanstream<_CharT, _Traits>& __x, basic_spanstream<_CharT, _Traits>& __y) {
+_LIBCPP_HIDE_FROM_ABI void swap(basic_spanstream<_CharT, _Traits>& __x, basic_spanstream<_CharT, _Traits>& __y) {
   __x.swap(__y);
 }
 
-using spanstream = basic_spanstream<char>;
+using std::spanstream;
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
-using wspanstream = basic_spanstream<wchar_t>;
+using std::wspanstream;
 #  endif
 
 #endif // _LIBCPP_STD_VER >= 23

>From 7c389645bd1a1bfb2bb11c60e39f6c34af136bfc Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Thu, 29 Feb 2024 11:05:55 +0200
Subject: [PATCH 05/29] Tests: `spanbuf` constructor tests

---
 .../ispanstream/types.compile.pass.cpp        |  14 +-
 .../std/input.output/span.streams/macros.h    |  18 ++
 .../ospanstream/types.compile.pass.cpp        |  14 +-
 .../spanbuf/spanbuf.cons/default.pass.cpp     |  25 +-
 .../spanbuf/spanbuf.cons/mode.pass.cpp        |  96 ++++++++
 .../spanbuf/spanbuf.cons/move.pass.cpp        | 224 ++++++++++++++++++
 .../spanbuf/spanbuf.cons/span.mode.pass.cpp   | 155 ++++++++++++
 .../spanbuf/types.compile.pass.cpp            |  14 +-
 .../spanstream/types.compile.pass.cpp         |  14 +-
 .../std/input.output/span.streams/types.h     |  73 ++++++
 10 files changed, 615 insertions(+), 32 deletions(-)
 create mode 100644 libcxx/test/std/input.output/span.streams/macros.h
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/types.h

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
index 9615d270116ee4..c566a3fce647dc 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
@@ -30,18 +30,18 @@
 #include "constexpr_char_traits.h"
 #include "test_macros.h"
 
-template <typename CharT, typename Traits = std::char_traits<CharT>>
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
-  using SpStream = std::basic_ispanstream<CharT, Traits>;
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
 
   // Types
 
-  static_assert(std::is_base_of_v<std::basic_istream<CharT, Traits>, SpStream>);
+  static_assert(std::is_base_of_v<std::basic_istream<CharT, TraitsT>, SpStream>);
   static_assert(std::is_same_v<typename SpStream::char_type, CharT>);
-  static_assert(std::is_same_v<typename SpStream::int_type, typename Traits::int_type>);
-  static_assert(std::is_same_v<typename SpStream::pos_type, typename Traits::pos_type>);
-  static_assert(std::is_same_v<typename SpStream::off_type, typename Traits::off_type>);
-  static_assert(std::is_same_v<typename SpStream::traits_type, Traits>);
+  static_assert(std::is_same_v<typename SpStream::int_type, typename TraitsT::int_type>);
+  static_assert(std::is_same_v<typename SpStream::pos_type, typename TraitsT::pos_type>);
+  static_assert(std::is_same_v<typename SpStream::off_type, typename TraitsT::off_type>);
+  static_assert(std::is_same_v<typename SpStream::traits_type, TraitsT>);
 
   // Copy properties
 
diff --git a/libcxx/test/std/input.output/span.streams/macros.h b/libcxx/test/std/input.output/span.streams/macros.h
new file mode 100644
index 00000000000000..679686eaa41a82
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/macros.h
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEST_STD_INPUTOUTPUT_SPANSTREAMS_MACROS_H
+#define TEST_STD_INPUTOUTPUT_SPANSTREAMS_MACROS_H
+
+#include "make_string.h"
+
+#define CS(S) MAKE_CSTRING(CharT, S)
+#define ST(S, a) std::basic_string<CharT, TraitsT, AllocT>(MAKE_CSTRING(CharT, S), MKSTR_LEN(CharT, S), a)
+#define SV(S) std::basic_string_view<CharT, TraitsT>(MAKE_CSTRING(CharT, S), MKSTR_LEN(CharT, S))
+
+#endif // TEST_STD_INPUTOUTPUT_SPANSTREAMS_MACROS_H
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
index e5a9e574eb39f7..595770aa5bd6b0 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
@@ -30,18 +30,18 @@
 #include "constexpr_char_traits.h"
 #include "test_macros.h"
 
-template <typename CharT, typename Traits = std::char_traits<CharT>>
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
-  using SpStream = std::basic_ospanstream<CharT, Traits>;
+  using SpStream = std::basic_ospanstream<CharT, TraitsT>;
 
   // Types
 
-  static_assert(std::is_base_of_v<std::basic_ostream<CharT, Traits>, SpStream>);
+  static_assert(std::is_base_of_v<std::basic_ostream<CharT, TraitsT>, SpStream>);
   static_assert(std::is_same_v<typename SpStream::char_type, CharT>);
-  static_assert(std::is_same_v<typename SpStream::int_type, typename Traits::int_type>);
-  static_assert(std::is_same_v<typename SpStream::pos_type, typename Traits::pos_type>);
-  static_assert(std::is_same_v<typename SpStream::off_type, typename Traits::off_type>);
-  static_assert(std::is_same_v<typename SpStream::traits_type, Traits>);
+  static_assert(std::is_same_v<typename SpStream::int_type, typename TraitsT::int_type>);
+  static_assert(std::is_same_v<typename SpStream::pos_type, typename TraitsT::pos_type>);
+  static_assert(std::is_same_v<typename SpStream::off_type, typename TraitsT::off_type>);
+  static_assert(std::is_same_v<typename SpStream::traits_type, TraitsT>);
 
   // Copy properties
 
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
index 4675c0e5fc2990..4c6b1ae3080d9e 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
@@ -21,19 +21,36 @@
 #include <spanstream>
 
 #include "constexpr_char_traits.h"
+#include "nasty_string.h"
 #include "test_macros.h"
 
-template <typename CharT, typename Traits = std::char_traits<CharT>>
-void test() {
-  using SpanBuf = std::basic_spanbuf<CharT, Traits>;
+void test_sfinae_with_nasty_char() {
+  using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
+
+  static_assert(std::default_initializable<SpBuf>);
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test_sfinae() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
-  static_assert(std::default_initializable<SpanBuf>);
+  static_assert(std::default_initializable<SpBuf>);
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpanBuf = std::basic_spanbuf<CharT, TraitsT>;
 
   SpanBuf spBuf;
+  assert(spBuf.span().data() == nullptr);
   assert(spBuf.span().empty());
+  assert(spBuf.span().size() == 0);
 }
 
 int main(int, char**) {
+  test_sfinae_with_nasty_char();
+  test_sfinae<char>();
+  test_sfinae<char, constexpr_char_traits<char>>();
   test<char>();
   test<char, constexpr_char_traits<char>>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
new file mode 100644
index 00000000000000..5a497e5b3238c0
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
@@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     explicit basic_spanbuf(ios_base::openmode which);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "nasty_string.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+#include "../../types.h"
+
+void test_sfinae_with_nasty_char() {
+  using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
+
+  static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test_sfinae() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  // `Mode`
+  static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpBuf, const NonMode>);
+  static_assert(!test_convertible<SpBuf, const NonMode>());
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  static_assert(std::default_initializable<SpBuf>);
+
+  // Mode: `in`
+  {
+    SpBuf spBuf(std::ios_base::in);
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: `out`
+  {
+    SpBuf spBuf(std::ios_base::out);
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpBuf spBuf(std::ios_base::out | std::ios_base::in | std::ios_base::binary);
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test_sfinae_with_nasty_char();
+  test_sfinae<char>();
+  test_sfinae<char, constexpr_char_traits<char>>();
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test_sfinae<wchar_t>();
+  test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
new file mode 100644
index 00000000000000..cfc67b07ea3030
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
@@ -0,0 +1,224 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     basic_spanbuf(basic_spanbuf&& rhs);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "nasty_string.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT>
+struct TestSpanBuf : std::basic_spanbuf<CharT, TraitsT> {
+  using std::basic_spanbuf<CharT, TraitsT>::basic_spanbuf;
+
+  TestSpanBuf(std::basic_spanbuf<CharT, TraitsT>&& rhs) : std::basic_spanbuf<CharT, TraitsT>(std::move(rhs)) {}
+
+  void check_postconditions(TestSpanBuf<CharT, TraitsT> const& rhs_p) const {
+    assert(this->span().data() == rhs_p.span().data());
+    assert(this->span().size() == rhs_p.span().size());
+    assert(this->eback() == rhs_p.eback());
+    assert(this->gptr() == rhs_p.gptr());
+    assert(this->egptr() == rhs_p.egptr());
+    assert(this->pbase() == rhs_p.pbase());
+    assert(this->pptr() == rhs_p.pptr());
+    assert(this->epptr() == rhs_p.epptr());
+    assert(this->getloc() == rhs_p.getloc());
+  }
+};
+
+void test_sfinae_with_nasty_char() {
+  using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
+
+  static_assert(std::move_constructible<SpBuf>);
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test_sfinae() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  static_assert(std::move_constructible<SpBuf>);
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  {
+    // Empty `span`
+    {
+      // Mode: `ios_base::in`
+      {
+        SpBuf rhsSpBuf{std::ios_base::in};
+        SpBuf spBuf(std::move(rhsSpBuf));
+        assert(spBuf.span().data() == nullptr);
+        assert(spBuf.span().empty());
+        assert(spBuf.span().size() == 0);
+      }
+      // Mode: `ios_base::out`
+      {
+        SpBuf rhsSpBuf{std::ios_base::out};
+        SpBuf spBuf(std::move(rhsSpBuf));
+        assert(spBuf.span().data() == nullptr);
+        assert(spBuf.span().empty());
+        assert(spBuf.span().size() == 0);
+      }
+      // Mode: multiple
+      {
+        SpBuf rhsSpBuf{std::ios_base::out | std::ios_base::in};
+        SpBuf spBuf(std::move(rhsSpBuf));
+        assert(spBuf.span().data() == nullptr);
+        assert(spBuf.span().empty());
+        assert(spBuf.span().size() == 0);
+      }
+    }
+
+    // Non-empty `span`
+    {
+      CharT arr[4];
+      std::span<CharT> sp{arr};
+
+      // Mode: `ios_base::in`
+      {
+        SpBuf rhsSpBuf{sp, std::ios_base::in};
+        SpBuf spBuf(std::move(rhsSpBuf));
+        assert(spBuf.span().data() == arr);
+        assert(!spBuf.span().empty());
+        assert(spBuf.span().size() == 4);
+      }
+      // Mode `ios_base::out`
+      {
+        SpBuf rhsSpBuf{sp, std::ios_base::out};
+        SpBuf spBuf(std::move(rhsSpBuf));
+        assert(spBuf.span().data() == arr);
+        assert(spBuf.span().empty());
+        assert(spBuf.span().size() == 0);
+      }
+      // Mode: multiple
+      {
+        SpBuf rhsSpBuf{sp, std::ios_base::out | std::ios_base::in | std::ios_base::binary};
+        SpBuf spBuf(std::move(rhsSpBuf));
+        assert(spBuf.span().data() == arr);
+        assert(spBuf.span().empty());
+        assert(spBuf.span().size() == 0);
+      }
+    }
+  }
+
+  // Check post-conditions
+  {
+    // Empty `span`
+    {
+      {
+        std::span<CharT> sp;
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp);
+        TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
+        assert(rhsSpBuf.span().empty());
+        assert(spBuf.span().data() == nullptr);
+        spBuf.check_postconditions(rhsSpBuf);
+      }
+      // Mode: `ios_base::in`
+      {
+        std::span<CharT> sp;
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::in);
+        TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
+        assert(rhsSpBuf.span().empty());
+        assert(spBuf.span().data() == nullptr);
+        spBuf.check_postconditions(rhsSpBuf);
+      }
+      // Mode: `ios_base::out`
+      {
+        std::span<CharT> sp;
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::out);
+        TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
+        assert(rhsSpBuf.span().empty());
+        assert(spBuf.span().data() == nullptr);
+        spBuf.check_postconditions(rhsSpBuf);
+      }
+      // Mode: multiple
+      {
+        std::span<CharT> sp;
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::out | std::ios_base::in | std::ios_base::binary);
+        TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
+        assert(rhsSpBuf.span().empty());
+        assert(spBuf.span().data() == nullptr);
+        spBuf.check_postconditions(rhsSpBuf);
+      }
+    }
+
+    // Non-empty `span`
+    {
+      CharT arr[4];
+
+      {
+        std::span<CharT> sp{arr};
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp);
+        TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
+        assert(rhsSpBuf.span().empty());
+        assert(spBuf.span().data() == arr);
+        spBuf.check_postconditions(rhsSpBuf);
+      }
+      // Mode: `ios_base::in`
+      {
+        std::span<CharT> sp{arr};
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::in);
+        TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
+        assert(!rhsSpBuf.span().empty());
+        assert(spBuf.span().data() == arr);
+        spBuf.check_postconditions(rhsSpBuf);
+      }
+      // Mode: `ios_base::out`
+      {
+        std::span<CharT> sp{arr};
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::out);
+        TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
+        assert(rhsSpBuf.span().empty());
+        assert(spBuf.span().data() == arr);
+        spBuf.check_postconditions(rhsSpBuf);
+      }
+      // Mode: multiple
+      {
+        std::span<CharT> sp{arr};
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::out | std::ios_base::in | std::ios_base::binary);
+        TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
+        assert(rhsSpBuf.span().empty());
+        assert(spBuf.span().data() == arr);
+        spBuf.check_postconditions(rhsSpBuf);
+      }
+    }
+  }
+}
+
+int main(int, char**) {
+  test_sfinae_with_nasty_char();
+  test_sfinae<char>();
+  test_sfinae<char, constexpr_char_traits<char>>();
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
new file mode 100644
index 00000000000000..fb58235d8c1fe0
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
@@ -0,0 +1,155 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     explicit basic_spanbuf(std::span<charT> s,
+//                            ios_base::openmode which = ios_base::in | ios_base::out);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+#include <utility>
+
+#include "constexpr_char_traits.h"
+#include "nasty_string.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+#include "../../macros.h"
+#include "../../types.h"
+
+void test_sfinae_with_nasty_char() {
+  using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
+
+  static_assert(std::constructible_from<SpBuf, const std::span<nasty_char>, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test_sfinae() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  // `Mode`
+  static_assert(std::constructible_from<SpBuf, const std::span<CharT>, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpBuf, const std::span<CharT>, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpBuf, const std::span<CharT>, const NonMode>);
+  static_assert(!test_convertible<SpBuf, const std::span<CharT>, const NonMode>());
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  static_assert(std::default_initializable<SpBuf>);
+
+  // Empty `span`
+  {
+    std::span<CharT> sp{};
+
+    // Mode: `ios_base::in`
+    {
+      SpBuf spBuf(sp, std::ios_base::in);
+      assert(spBuf.span().data() == nullptr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+    {
+      SpBuf spBuf(std::as_const(sp), std::ios_base::in);
+      assert(spBuf.span().data() == nullptr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+    // Mode: `ios_base::out`
+    {
+      SpBuf spBuf(sp, std::ios_base::out);
+      assert(spBuf.span().data() == nullptr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+    {
+      SpBuf spBuf(std::as_const(sp), std::ios_base::out);
+      assert(spBuf.span().data() == nullptr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+  }
+
+  // Non-empty `span`
+  {
+    CharT arr[4];
+    std::span<CharT> sp{arr};
+
+    // Mode: `ios_base::in`
+    {
+      SpBuf spBuf(sp, std::ios_base::in);
+      assert(spBuf.span().data() == arr);
+      assert(!spBuf.span().empty());
+      assert(spBuf.span().size() == 4);
+    }
+    {
+      SpBuf spBuf(std::as_const(sp), std::ios_base::in);
+      assert(spBuf.span().data() == arr);
+      assert(!spBuf.span().empty());
+      assert(spBuf.span().size() == 4);
+    }
+    // Mode `ios_base::out`
+    {
+      SpBuf spBuf(sp, std::ios_base::out);
+      assert(spBuf.span().data() == arr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+    {
+      SpBuf spBuf(std::as_const(sp), std::ios_base::out);
+      assert(spBuf.span().data() == arr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+    // Mode: multiple
+    {
+      SpBuf spBuf(sp, std::ios_base::out | std::ios_base::in);
+      assert(spBuf.span().data() == arr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+    {
+      SpBuf spBuf(std::as_const(sp), std::ios_base::out | std::ios_base::in | std::ios_base::binary);
+      assert(spBuf.span().data() == arr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+  }
+}
+
+int main(int, char**) {
+  test_sfinae_with_nasty_char();
+  test_sfinae<char>();
+  test_sfinae<char, constexpr_char_traits<char>>();
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test_sfinae<wchar_t>();
+  test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
\ No newline at end of file
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
index a8cc07ed524ea8..4c18422ebff28c 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
@@ -30,18 +30,18 @@
 #include "constexpr_char_traits.h"
 #include "test_macros.h"
 
-template <typename CharT, typename Traits = std::char_traits<CharT>>
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
-  using SpBuf = std::basic_spanbuf<CharT, Traits>;
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
   // Types
 
-  static_assert(std::is_base_of_v<std::basic_streambuf<CharT, Traits>, SpBuf>);
+  static_assert(std::is_base_of_v<std::basic_streambuf<CharT, TraitsT>, SpBuf>);
   static_assert(std::is_same_v<typename SpBuf::char_type, CharT>);
-  static_assert(std::is_same_v<typename SpBuf::int_type, typename Traits::int_type>);
-  static_assert(std::is_same_v<typename SpBuf::pos_type, typename Traits::pos_type>);
-  static_assert(std::is_same_v<typename SpBuf::off_type, typename Traits::off_type>);
-  static_assert(std::is_same_v<typename SpBuf::traits_type, Traits>);
+  static_assert(std::is_same_v<typename SpBuf::int_type, typename TraitsT::int_type>);
+  static_assert(std::is_same_v<typename SpBuf::pos_type, typename TraitsT::pos_type>);
+  static_assert(std::is_same_v<typename SpBuf::off_type, typename TraitsT::off_type>);
+  static_assert(std::is_same_v<typename SpBuf::traits_type, TraitsT>);
 
   // Copy properties
 
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
index 5714834be2ce11..67d29cf041d9cc 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
@@ -30,18 +30,18 @@
 #include "constexpr_char_traits.h"
 #include "test_macros.h"
 
-template <typename CharT, typename Traits = std::char_traits<CharT>>
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
-  using SpStream = std::basic_spanstream<CharT, Traits>;
+  using SpStream = std::basic_spanstream<CharT, TraitsT>;
 
   // Types
 
-  static_assert(std::is_base_of_v<std::basic_iostream<CharT, Traits>, SpStream>);
+  static_assert(std::is_base_of_v<std::basic_iostream<CharT, TraitsT>, SpStream>);
   static_assert(std::is_same_v<typename SpStream::char_type, CharT>);
-  static_assert(std::is_same_v<typename SpStream::int_type, typename Traits::int_type>);
-  static_assert(std::is_same_v<typename SpStream::pos_type, typename Traits::pos_type>);
-  static_assert(std::is_same_v<typename SpStream::off_type, typename Traits::off_type>);
-  static_assert(std::is_same_v<typename SpStream::traits_type, Traits>);
+  static_assert(std::is_same_v<typename SpStream::int_type, typename TraitsT::int_type>);
+  static_assert(std::is_same_v<typename SpStream::pos_type, typename TraitsT::pos_type>);
+  static_assert(std::is_same_v<typename SpStream::off_type, typename TraitsT::off_type>);
+  static_assert(std::is_same_v<typename SpStream::traits_type, TraitsT>);
 
   // Copy properties
 
diff --git a/libcxx/test/std/input.output/span.streams/types.h b/libcxx/test/std/input.output/span.streams/types.h
new file mode 100644
index 00000000000000..18788a56579dcb
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/types.h
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEST_STD_INPUTOUTPUT_SPANSTREAMS_TYPES_H
+#define TEST_STD_INPUTOUTPUT_SPANSTREAMS_TYPES_H
+
+#include <string_view>
+#include <concepts>
+
+#include "test_macros.h"
+
+// template <typename CharT, class Traits = std::char_traits<CharT>>
+// class ConstConvertibleStringView {
+// public:
+//   explicit ConstConvertibleStringView(const CharT* cs) : cs_{cs} {}
+
+//   operator std::basic_string_view<CharT, Traits>() = delete;
+//   operator std::basic_string_view<CharT, Traits>() const { return std::basic_string_view<CharT, Traits>(cs_); }
+
+// private:
+//   const CharT* cs_;
+// };
+
+// static_assert(!std::constructible_from<std::basic_string_view<char>, ConstConvertibleStringView<char>>);
+// static_assert(!std::convertible_to<ConstConvertibleStringView<char>, std::basic_string_view<char>>);
+
+// static_assert(std::constructible_from<std::basic_string_view<char>, const ConstConvertibleStringView<char>>);
+// static_assert(std::convertible_to<const ConstConvertibleStringView<char>, std::basic_string_view<char>>);
+
+// #ifndef TEST_HAS_NO_WIDE_CHARACTERS
+// static_assert(!std::constructible_from<std::basic_string_view<wchar_t>, ConstConvertibleStringView<wchar_t>>);
+// static_assert(!std::convertible_to<ConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>);
+
+// static_assert(std::constructible_from<std::basic_string_view<wchar_t>, const ConstConvertibleStringView<wchar_t>>);
+// static_assert(std::convertible_to<const ConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>);
+// #endif
+
+// template <typename CharT, class Traits = std::char_traits<CharT>>
+// class NonConstConvertibleStringView {
+// public:
+//   explicit NonConstConvertibleStringView(const CharT* cs) : cs_{cs} {}
+
+//   operator std::basic_string_view<CharT, Traits>() { return std::basic_string_view<CharT, Traits>(cs_); }
+//   operator std::basic_string_view<CharT, Traits>() const = delete;
+
+// private:
+//   const CharT* cs_;
+// };
+
+// static_assert(std::constructible_from<std::basic_string_view<char>, NonConstConvertibleStringView<char>>);
+// static_assert(std::convertible_to<NonConstConvertibleStringView<char>, std::basic_string_view<char>>);
+
+// static_assert(!std::constructible_from<std::basic_string_view<char>, const NonConstConvertibleStringView<char>>);
+// static_assert(!std::convertible_to<const NonConstConvertibleStringView<char>, std::basic_string_view<char>>);
+
+// #ifndef TEST_HAS_NO_WIDE_CHARACTERS
+// static_assert(std::constructible_from<std::basic_string_view<wchar_t>, NonConstConvertibleStringView<wchar_t>>);
+// static_assert(std::convertible_to<NonConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>);
+
+// static_assert(!std::constructible_from<std::basic_string_view<wchar_t>, const NonConstConvertibleStringView<wchar_t>>);
+// static_assert(!std::convertible_to<const NonConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>);
+// #endif
+
+struct SomeObject {};
+
+struct NonMode {};
+
+#endif // TEST_STD_INPUTOUTPUT_SPANSTREAMS_TYPES_H

>From 5bd573ec7d869dd9e9afc8b7a5fa953f0959be9e Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 09:49:14 +0200
Subject: [PATCH 06/29] Tests: tweaks

---
 .../ospanstream/types.compile.pass.cpp        | 11 +++---
 .../spanbuf/spanbuf.cons/default.pass.cpp     | 20 +---------
 .../spanbuf/spanbuf.cons/mode.pass.cpp        |  9 ++++-
 .../spanbuf/spanbuf.cons/move.pass.cpp        | 24 ++++++++++--
 .../spanbuf/spanbuf.cons/span.mode.pass.cpp   | 38 +++++++++++++++++--
 .../spanbuf/types.compile.pass.cpp            | 11 +++---
 .../spanstream/types.compile.pass.cpp         | 11 +++---
 7 files changed, 83 insertions(+), 41 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
index 595770aa5bd6b0..5374011f61cc27 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
@@ -28,12 +28,17 @@
 #include <type_traits>
 
 #include "constexpr_char_traits.h"
+#include "nasty_string.h"
 #include "test_macros.h"
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
   using SpStream = std::basic_ospanstream<CharT, TraitsT>;
 
+  // Constructors
+
+  static_assert(!std::is_default_constructible_v<SpStream>);
+
   // Types
 
   static_assert(std::is_base_of_v<std::basic_ostream<CharT, TraitsT>, SpStream>);
@@ -50,11 +55,6 @@ void test() {
 
   // Move properties
 
-  static_assert(!std::is_copy_constructible_v<SpStream>);
-  static_assert(!std::is_copy_assignable_v<SpStream>);
-
-  // Move properties
-
   static_assert(std::is_move_constructible_v<SpStream>);
   static_assert(std::is_move_assignable_v<SpStream>);
 }
@@ -62,6 +62,7 @@ void test() {
 void test() {
   test<char>();
   test<char, constexpr_char_traits<char>>();
+  test<nasty_char, nasty_char_traits>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test<wchar_t>();
   test<wchar_t, constexpr_char_traits<wchar_t>>();
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
index 4c6b1ae3080d9e..a94551a96e0002 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
@@ -24,33 +24,17 @@
 #include "nasty_string.h"
 #include "test_macros.h"
 
-void test_sfinae_with_nasty_char() {
-  using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
-
-  static_assert(std::default_initializable<SpBuf>);
-}
-
-template <typename CharT, typename TraitsT = std::char_traits<CharT>>
-void test_sfinae() {
-  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
-
-  static_assert(std::default_initializable<SpBuf>);
-}
-
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
-  using SpanBuf = std::basic_spanbuf<CharT, TraitsT>;
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
-  SpanBuf spBuf;
+  SpBuf spBuf;
   assert(spBuf.span().data() == nullptr);
   assert(spBuf.span().empty());
   assert(spBuf.span().size() == 0);
 }
 
 int main(int, char**) {
-  test_sfinae_with_nasty_char();
-  test_sfinae<char>();
-  test_sfinae<char, constexpr_char_traits<char>>();
   test<char>();
   test<char, constexpr_char_traits<char>>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
index 5a497e5b3238c0..b452b6e80248e1 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
@@ -33,15 +33,20 @@
 void test_sfinae_with_nasty_char() {
   using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
 
+  // Mode
   static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
   static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpBuf, const NonMode>);
+  static_assert(!test_convertible<SpBuf, const NonMode>());
 }
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
   using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
-  // `Mode`
+  // Mode
   static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
   static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
 
@@ -72,7 +77,7 @@ void test() {
   }
   // Mode: multiple
   {
-    SpBuf spBuf(std::ios_base::out | std::ios_base::in | std::ios_base::binary);
+    SpBuf spBuf(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
     assert(spBuf.span().data() == nullptr);
     assert(spBuf.span().empty());
     assert(spBuf.span().size() == 0);
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
index cfc67b07ea3030..b32f6703981af6 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
@@ -32,7 +32,7 @@ template <typename CharT, typename TraitsT>
 struct TestSpanBuf : std::basic_spanbuf<CharT, TraitsT> {
   using std::basic_spanbuf<CharT, TraitsT>::basic_spanbuf;
 
-  TestSpanBuf(std::basic_spanbuf<CharT, TraitsT>&& rhs) : std::basic_spanbuf<CharT, TraitsT>(std::move(rhs)) {}
+  TestSpanBuf(std::basic_spanbuf<CharT, TraitsT>&& rhs_p) : std::basic_spanbuf<CharT, TraitsT>(std::move(rhs_p)) {}
 
   void check_postconditions(TestSpanBuf<CharT, TraitsT> const& rhs_p) const {
     assert(this->span().data() == rhs_p.span().data());
@@ -67,6 +67,14 @@ void test() {
   {
     // Empty `span`
     {
+      // Mode: default
+      {
+        SpBuf rhsSpBuf;
+        SpBuf spBuf(std::move(rhsSpBuf));
+        assert(spBuf.span().data() == nullptr);
+        assert(spBuf.span().empty());
+        assert(spBuf.span().size() == 0);
+      }
       // Mode: `ios_base::in`
       {
         SpBuf rhsSpBuf{std::ios_base::in};
@@ -98,6 +106,14 @@ void test() {
       CharT arr[4];
       std::span<CharT> sp{arr};
 
+      // Mode: default
+      {
+        SpBuf rhsSpBuf{sp};
+        SpBuf spBuf(std::move(rhsSpBuf));
+        assert(spBuf.span().data() == arr);
+        assert(spBuf.span().empty());
+        assert(spBuf.span().size() == 0);
+      }
       // Mode: `ios_base::in`
       {
         SpBuf rhsSpBuf{sp, std::ios_base::in};
@@ -129,6 +145,7 @@ void test() {
   {
     // Empty `span`
     {
+      // Mode: default
       {
         std::span<CharT> sp;
         TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp);
@@ -158,7 +175,7 @@ void test() {
       // Mode: multiple
       {
         std::span<CharT> sp;
-        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::out | std::ios_base::in | std::ios_base::binary);
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
         TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
         assert(rhsSpBuf.span().empty());
         assert(spBuf.span().data() == nullptr);
@@ -170,6 +187,7 @@ void test() {
     {
       CharT arr[4];
 
+      // Mode: default
       {
         std::span<CharT> sp{arr};
         TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp);
@@ -199,7 +217,7 @@ void test() {
       // Mode: multiple
       {
         std::span<CharT> sp{arr};
-        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::out | std::ios_base::in | std::ios_base::binary);
+        TestSpanBuf<CharT, TraitsT> rhsSpBuf(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
         TestSpanBuf<CharT, TraitsT> spBuf(std::move(static_cast<SpBuf&>(rhsSpBuf)));
         assert(rhsSpBuf.span().empty());
         assert(spBuf.span().data() == arr);
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
index fb58235d8c1fe0..ff600b92e5c025 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
@@ -36,15 +36,20 @@
 void test_sfinae_with_nasty_char() {
   using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
 
+  // Mode
   static_assert(std::constructible_from<SpBuf, const std::span<nasty_char>, std::ios_base::openmode>);
   static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpBuf, const std::span<nasty_char>, const NonMode>);
+  static_assert(!test_convertible<SpBuf, const NonMode>());
 }
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
   using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
-  // `Mode`
+  // Mode
   static_assert(std::constructible_from<SpBuf, const std::span<CharT>, std::ios_base::openmode>);
   static_assert(!test_convertible<SpBuf, const std::span<CharT>, std::ios_base::openmode>());
 
@@ -63,6 +68,13 @@ void test() {
   {
     std::span<CharT> sp{};
 
+    // Mode: default
+    {
+      SpBuf spBuf(sp);
+      assert(spBuf.span().data() == nullptr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
     // Mode: `ios_base::in`
     {
       SpBuf spBuf(sp, std::ios_base::in);
@@ -89,6 +101,19 @@ void test() {
       assert(spBuf.span().empty());
       assert(spBuf.span().size() == 0);
     }
+    // Mode: multiple
+    {
+      SpBuf spBuf(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+      assert(spBuf.span().data() == nullptr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
+    {
+      SpBuf spBuf(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+      assert(spBuf.span().data() == nullptr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
   }
 
   // Non-empty `span`
@@ -96,6 +121,13 @@ void test() {
     CharT arr[4];
     std::span<CharT> sp{arr};
 
+    // Mode: default
+    {
+      SpBuf spBuf(sp);
+      assert(spBuf.span().data() == arr);
+      assert(spBuf.span().empty());
+      assert(spBuf.span().size() == 0);
+    }
     // Mode: `ios_base::in`
     {
       SpBuf spBuf(sp, std::ios_base::in);
@@ -124,13 +156,13 @@ void test() {
     }
     // Mode: multiple
     {
-      SpBuf spBuf(sp, std::ios_base::out | std::ios_base::in);
+      SpBuf spBuf(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
       assert(spBuf.span().data() == arr);
       assert(spBuf.span().empty());
       assert(spBuf.span().size() == 0);
     }
     {
-      SpBuf spBuf(std::as_const(sp), std::ios_base::out | std::ios_base::in | std::ios_base::binary);
+      SpBuf spBuf(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
       assert(spBuf.span().data() == arr);
       assert(spBuf.span().empty());
       assert(spBuf.span().size() == 0);
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
index 4c18422ebff28c..dec47dbf7b8ebc 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
@@ -28,12 +28,17 @@
 #include <type_traits>
 
 #include "constexpr_char_traits.h"
+#include "nasty_string.h"
 #include "test_macros.h"
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
   using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
+  // Constructors
+
+  static_assert(std::is_default_constructible_v<SpBuf>);
+
   // Types
 
   static_assert(std::is_base_of_v<std::basic_streambuf<CharT, TraitsT>, SpBuf>);
@@ -50,11 +55,6 @@ void test() {
 
   // Move properties
 
-  static_assert(!std::is_copy_constructible_v<SpBuf>);
-  static_assert(!std::is_copy_assignable_v<SpBuf>);
-
-  // Move properties
-
   static_assert(std::is_move_constructible_v<SpBuf>);
   static_assert(std::is_move_assignable_v<SpBuf>);
 }
@@ -62,6 +62,7 @@ void test() {
 void test() {
   test<char>();
   test<char, constexpr_char_traits<char>>();
+  test<nasty_char, nasty_char_traits>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test<wchar_t>();
   test<wchar_t, constexpr_char_traits<wchar_t>>();
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
index 67d29cf041d9cc..7c33c604237a3b 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
@@ -28,12 +28,17 @@
 #include <type_traits>
 
 #include "constexpr_char_traits.h"
+#include "nasty_string.h"
 #include "test_macros.h"
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
   using SpStream = std::basic_spanstream<CharT, TraitsT>;
 
+  // Constructors
+
+  static_assert(!std::is_default_constructible_v<SpStream>);
+
   // Types
 
   static_assert(std::is_base_of_v<std::basic_iostream<CharT, TraitsT>, SpStream>);
@@ -50,11 +55,6 @@ void test() {
 
   // Move properties
 
-  static_assert(!std::is_copy_constructible_v<SpStream>);
-  static_assert(!std::is_copy_assignable_v<SpStream>);
-
-  // Move properties
-
   static_assert(std::is_move_constructible_v<SpStream>);
   static_assert(std::is_move_assignable_v<SpStream>);
 }
@@ -62,6 +62,7 @@ void test() {
 void test() {
   test<char>();
   test<char, constexpr_char_traits<char>>();
+  test<nasty_char, nasty_char_traits>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test<wchar_t>();
   test<wchar_t, constexpr_char_traits<wchar_t>>();

>From ff24a70f56def31b784679db124c1d03321d017d Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 09:49:44 +0200
Subject: [PATCH 07/29] Tests: `ispanstream` constructors - WIP

---
 .../ispanstream.cons/move.pass.cpp            |  81 +++++++++++
 .../ispanstream/ispanstream.cons/ros.pass.cpp |  60 ++++++++
 .../ispanstream.cons/span.mode.pass.cpp       | 136 ++++++++++++++++++
 .../ispanstream/types.compile.pass.cpp        |  11 +-
 4 files changed, 283 insertions(+), 5 deletions(-)
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
new file mode 100644
index 00000000000000..ce711deedc140d
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ispanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     basic_ispanstream(basic_ispanstream&& rhs);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "nasty_string.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream rhsSpStream{sp};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream rhsSpStream{sp, std::ios_base::in};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream rhsSpStream{sp, std::ios_base::out};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream rhsSpStream{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
new file mode 100644
index 00000000000000..d4c9b2a765ac1b
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ispanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     template<class ROS> explicit basic_ispanstream(ROS&& s);
+
+#include <cassert>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "nasty_string.h"
+#include "test_macros.h"
+
+void test_sfinae_with_nasty_char() {
+  using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
+
+  // TODO:
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test_sfinae() {
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+
+  // TODO:
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+
+  // TODO:
+}
+
+int main(int, char**) {
+  test_sfinae_with_nasty_char();
+  test_sfinae<char>();
+  test_sfinae<char, constexpr_char_traits<char>>();
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
new file mode 100644
index 00000000000000..0938e35d0fb60a
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
@@ -0,0 +1,136 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ispanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     explicit basic_ispanstream(std::span<charT> s,
+//                                ios_base::openmode which = ios_base::in);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+#include <utility>
+
+#include "constexpr_char_traits.h"
+#include "nasty_string.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+#include "../../macros.h"
+#include "../../types.h"
+
+void test_sfinae_with_nasty_char() {
+  using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
+
+  // Mode
+  static_assert(std::constructible_from<SpStream, const std::span<nasty_char>, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpStream, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpStream, const std::span<nasty_char>, const NonMode>);
+  static_assert(!test_convertible<SpStream, const std::span<nasty_char>, const NonMode>());
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test_sfinae() {
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+
+  // Mode
+  static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpStream, const std::span<CharT>, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpStream, const std::span<CharT>, const NonMode>);
+  static_assert(!test_convertible<SpStream, const std::span<CharT>, const NonMode>());
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream sps(sp);
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  {
+    SpStream sps(std::as_const(sp));
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream sps(sp, std::ios_base::in);
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::in);
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream sps(sp, std::ios_base::out);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::out);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream sps(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test_sfinae_with_nasty_char();
+  test_sfinae<char>();
+  test_sfinae<char, constexpr_char_traits<char>>();
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test_sfinae<wchar_t>();
+  test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
\ No newline at end of file
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
index c566a3fce647dc..ddd15186b7c189 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
@@ -28,12 +28,17 @@
 #include <type_traits>
 
 #include "constexpr_char_traits.h"
+#include "nasty_string.h"
 #include "test_macros.h"
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
   using SpStream = std::basic_ispanstream<CharT, TraitsT>;
 
+  // Constructors
+
+  static_assert(!std::is_default_constructible_v<SpStream>);
+
   // Types
 
   static_assert(std::is_base_of_v<std::basic_istream<CharT, TraitsT>, SpStream>);
@@ -50,11 +55,6 @@ void test() {
 
   // Move properties
 
-  static_assert(!std::is_copy_constructible_v<SpStream>);
-  static_assert(!std::is_copy_assignable_v<SpStream>);
-
-  // Move properties
-
   static_assert(std::is_move_constructible_v<SpStream>);
   static_assert(std::is_move_assignable_v<SpStream>);
 }
@@ -62,6 +62,7 @@ void test() {
 void test() {
   test<char>();
   test<char, constexpr_char_traits<char>>();
+  test<nasty_char, nasty_char_traits>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test<wchar_t>();
   test<wchar_t, constexpr_char_traits<wchar_t>>();

>From bc637c30eefc397f41a6565439e0a8eead14ac81 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 10:52:23 +0200
Subject: [PATCH 08/29] Implementation: fixed module and forward declarations

---
 libcxx/include/libcxx.imp             | 2 +-
 libcxx/modules/std/spanstream.inc     | 4 ++--
 libcxx/utils/generate_iwyu_mapping.py | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libcxx/include/libcxx.imp b/libcxx/include/libcxx.imp
index 5818c4916751f9..077e591cbf393f 100644
--- a/libcxx/include/libcxx.imp
+++ b/libcxx/include/libcxx.imp
@@ -434,7 +434,7 @@
   { include: [ "<__fwd/ostream.h>", "private", "<iosfwd>", "public" ] },
   { include: [ "<__fwd/pair.h>", "private", "<utility>", "public" ] },
   { include: [ "<__fwd/span.h>", "private", "<span>", "public" ] },
-  { include: [ "<__fwd/spanstream.h>", "private", "<spanstream>", "public" ] },
+  { include: [ "<__fwd/spanstream.h>", "private", "<iosfwd>", "public" ] },
   { include: [ "<__fwd/sstream.h>", "private", "<iosfwd>", "public" ] },
   { include: [ "<__fwd/streambuf.h>", "private", "<iosfwd>", "public" ] },
   { include: [ "<__fwd/string.h>", "private", "<string>", "public" ] },
diff --git a/libcxx/modules/std/spanstream.inc b/libcxx/modules/std/spanstream.inc
index e6383a185e0798..c9a50f0c2b8410 100644
--- a/libcxx/modules/std/spanstream.inc
+++ b/libcxx/modules/std/spanstream.inc
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 export namespace std {
-#if 0
+#if _LIBCPP_STD_VER >= 23
   using std::basic_spanbuf;
 
   using std::swap;
@@ -38,5 +38,5 @@ export namespace std {
 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
   using std::wspanstream;
 #  endif
-#endif
+#endif // _LIBCPP_STD_VER >= 23
 } // namespace std
diff --git a/libcxx/utils/generate_iwyu_mapping.py b/libcxx/utils/generate_iwyu_mapping.py
index 8ab7b86299edca..76e55b60a07df1 100644
--- a/libcxx/utils/generate_iwyu_mapping.py
+++ b/libcxx/utils/generate_iwyu_mapping.py
@@ -38,7 +38,7 @@ def IWYU_mapping(header: str) -> typing.Optional[typing.List[str]]:
         return ["utility"]
     elif header == "__fwd/subrange.h":
         return ["ranges"]
-    elif re.match("__fwd/(fstream|ios|istream|ostream|sstream|streambuf)[.]h", header):
+    elif re.match("__fwd/(fstream|ios|istream|ostream|spanstream|sstream|streambuf)[.]h", header):
         return ["iosfwd"]
     # Handle remaining forward declaration headers
     elif re.match("__fwd/(.+)[.]h", header):

>From 967bdd0f907472ad48b02cd27bd64a3170b9ebad Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 10:56:25 +0200
Subject: [PATCH 09/29] Implementation: fixed python code formatting

---
 libcxx/utils/generate_iwyu_mapping.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libcxx/utils/generate_iwyu_mapping.py b/libcxx/utils/generate_iwyu_mapping.py
index 76e55b60a07df1..b5098fafedbb48 100644
--- a/libcxx/utils/generate_iwyu_mapping.py
+++ b/libcxx/utils/generate_iwyu_mapping.py
@@ -38,7 +38,9 @@ def IWYU_mapping(header: str) -> typing.Optional[typing.List[str]]:
         return ["utility"]
     elif header == "__fwd/subrange.h":
         return ["ranges"]
-    elif re.match("__fwd/(fstream|ios|istream|ostream|spanstream|sstream|streambuf)[.]h", header):
+    elif re.match(
+        "__fwd/(fstream|ios|istream|ostream|spanstream|sstream|streambuf)[.]h", header
+    ):
         return ["iosfwd"]
     # Handle remaining forward declaration headers
     elif re.match("__fwd/(.+)[.]h", header):

>From 5eee2e7a56e2b58716381a9417c9e94adec9b1aa Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 11:20:59 +0200
Subject: [PATCH 10/29] Implementation: updated transitive includes

---
 libcxx/test/libcxx/transitive_includes/cxx03.csv | 8 ++++++++
 libcxx/test/libcxx/transitive_includes/cxx11.csv | 8 ++++++++
 libcxx/test/libcxx/transitive_includes/cxx14.csv | 8 ++++++++
 libcxx/test/libcxx/transitive_includes/cxx17.csv | 8 ++++++++
 libcxx/test/libcxx/transitive_includes/cxx20.csv | 8 ++++++++
 libcxx/test/libcxx/transitive_includes/cxx23.csv | 7 +++++++
 libcxx/test/libcxx/transitive_includes/cxx26.csv | 7 +++++++
 7 files changed, 54 insertions(+)

diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index 678a986e522aa0..9ddfabc83c4b6c 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -741,6 +741,14 @@ span limits
 span stdexcept
 span type_traits
 span version
+spanstream cstddef
+spanstream initializer_list
+spanstream iostream
+spanstream limits
+spanstream span
+spanstream streambuf
+spanstream type_traits
+spanstream version
 sstream cstddef
 sstream istream
 sstream ostream
diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index c3875fa2cfc06f..f6ab0e508e2dd6 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -747,6 +747,14 @@ span limits
 span stdexcept
 span type_traits
 span version
+spanstream cstddef
+spanstream initializer_list
+spanstream iostream
+spanstream limits
+spanstream span
+spanstream streambuf
+spanstream type_traits
+spanstream version
 sstream cstddef
 sstream istream
 sstream ostream
diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index e28e0cd44fed95..b9adc215cf5e12 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -749,6 +749,14 @@ span limits
 span stdexcept
 span type_traits
 span version
+spanstream cstddef
+spanstream initializer_list
+spanstream iostream
+spanstream limits
+spanstream span
+spanstream streambuf
+spanstream type_traits
+spanstream version
 sstream cstddef
 sstream istream
 sstream ostream
diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv
index e28e0cd44fed95..b9adc215cf5e12 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx17.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv
@@ -749,6 +749,14 @@ span limits
 span stdexcept
 span type_traits
 span version
+spanstream cstddef
+spanstream initializer_list
+spanstream iostream
+spanstream limits
+spanstream span
+spanstream streambuf
+spanstream type_traits
+spanstream version
 sstream cstddef
 sstream istream
 sstream ostream
diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv
index eec71f4fc6282e..ee9a1ceb112ecc 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx20.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv
@@ -754,6 +754,14 @@ span limits
 span stdexcept
 span type_traits
 span version
+spanstream cstddef
+spanstream initializer_list
+spanstream iostream
+spanstream limits
+spanstream span
+spanstream streambuf
+spanstream type_traits
+spanstream version
 sstream cstddef
 sstream istream
 sstream ostream
diff --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv
index 64ff9261820a96..86619947c5157d 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -515,6 +515,13 @@ span initializer_list
 span limits
 span stdexcept
 span version
+spanstream cstddef
+spanstream initializer_list
+spanstream iostream
+spanstream limits
+spanstream span
+spanstream streambuf
+spanstream version
 sstream cstddef
 sstream istream
 sstream ostream
diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index 64ff9261820a96..86619947c5157d 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -515,6 +515,13 @@ span initializer_list
 span limits
 span stdexcept
 span version
+spanstream cstddef
+spanstream initializer_list
+spanstream iostream
+spanstream limits
+spanstream span
+spanstream streambuf
+spanstream version
 sstream cstddef
 sstream istream
 sstream ostream

>From 677a0acd4d7c3949e70ec325f41b909070c72649 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 11:45:01 +0200
Subject: [PATCH 11/29] Implementation: fix CI

---
 libcxx/include/spanstream | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index 16bbf04d81c559..814fa9a6f00e26 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -56,6 +56,7 @@
 
 #include <__assert> // all public C++ headers provide the assertion handler
 #include <__availability>
+#include <__concepts/convertible_to.h>
 #include <__config>
 #include <__fwd/spanstream.h>
 #include <__memory/addressof.h>

>From af2a74664c251248b6dc34725c8a701670b52c64 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 13:33:23 +0200
Subject: [PATCH 12/29] Implementation: try to fix CI

---
 .../ispanstream/ispanstream.cons/move.pass.cpp  |  1 -
 .../ispanstream/ispanstream.cons/ros.pass.cpp   |  4 ++++
 .../ispanstream.cons/span.mode.pass.cpp         |  4 ++++
 .../ispanstream/types.compile.pass.cpp          |  4 +++-
 .../ospanstream/types.compile.pass.cpp          |  4 +++-
 .../spanbuf/spanbuf.cons/default.pass.cpp       |  1 -
 .../spanbuf/spanbuf.cons/mode.pass.cpp          |  4 ++++
 .../spanbuf/spanbuf.cons/move.pass.cpp          | 17 -----------------
 .../spanbuf/spanbuf.cons/span.mode.pass.cpp     |  4 ++++
 .../span.streams/spanbuf/types.compile.pass.cpp |  4 +++-
 .../spanstream/types.compile.pass.cpp           |  4 +++-
 11 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
index ce711deedc140d..1b456a8a0ef38b 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
@@ -24,7 +24,6 @@
 #include <spanstream>
 
 #include "constexpr_char_traits.h"
-#include "nasty_string.h"
 #include "test_convertible.h"
 #include "test_macros.h"
 
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
index d4c9b2a765ac1b..421ba8ff10e169 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
@@ -25,11 +25,13 @@
 #include "nasty_string.h"
 #include "test_macros.h"
 
+#ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
   using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
 
   // TODO:
 }
+#endif // TEST_HAS_NO_NASTY_STRING
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
@@ -46,7 +48,9 @@ void test() {
 }
 
 int main(int, char**) {
+#ifndef TEST_HAS_NO_NASTY_STRING
   test_sfinae_with_nasty_char();
+#endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
   test<char>();
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
index 0938e35d0fb60a..cd793210e2c063 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
@@ -33,6 +33,7 @@
 #include "../../macros.h"
 #include "../../types.h"
 
+#ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
   using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
 
@@ -44,6 +45,7 @@ void test_sfinae_with_nasty_char() {
   static_assert(!std::constructible_from<SpStream, const std::span<nasty_char>, const NonMode>);
   static_assert(!test_convertible<SpStream, const std::span<nasty_char>, const NonMode>());
 }
+#endif // TEST_HAS_NO_NASTY_STRING
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
@@ -120,7 +122,9 @@ void test() {
 }
 
 int main(int, char**) {
+#ifndef TEST_HAS_NO_NASTY_STRING
   test_sfinae_with_nasty_char();
+#endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
   test<char>();
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
index ddd15186b7c189..9b492a9c59985e 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/types.compile.pass.cpp
@@ -60,9 +60,11 @@ void test() {
 }
 
 void test() {
+#ifndef TEST_HAS_NO_NASTY_STRING
+  test<nasty_char, nasty_char_traits>();
+#endif
   test<char>();
   test<char, constexpr_char_traits<char>>();
-  test<nasty_char, nasty_char_traits>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test<wchar_t>();
   test<wchar_t, constexpr_char_traits<wchar_t>>();
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
index 5374011f61cc27..71f76790d66fdf 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/types.compile.pass.cpp
@@ -60,9 +60,11 @@ void test() {
 }
 
 void test() {
+#ifndef TEST_HAS_NO_NASTY_STRING
+  test<nasty_char, nasty_char_traits>();
+#endif
   test<char>();
   test<char, constexpr_char_traits<char>>();
-  test<nasty_char, nasty_char_traits>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test<wchar_t>();
   test<wchar_t, constexpr_char_traits<wchar_t>>();
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
index a94551a96e0002..b76af127f43144 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/default.pass.cpp
@@ -21,7 +21,6 @@
 #include <spanstream>
 
 #include "constexpr_char_traits.h"
-#include "nasty_string.h"
 #include "test_macros.h"
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
index b452b6e80248e1..eb8b29de9fbff0 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
@@ -30,6 +30,7 @@
 
 #include "../../types.h"
 
+#ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
   using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
 
@@ -41,6 +42,7 @@ void test_sfinae_with_nasty_char() {
   static_assert(!std::constructible_from<SpBuf, const NonMode>);
   static_assert(!test_convertible<SpBuf, const NonMode>());
 }
+#endif // TEST_HAS_NO_NASTY_STRING
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
@@ -85,7 +87,9 @@ void test() {
 }
 
 int main(int, char**) {
+#ifndef TEST_HAS_NO_NASTY_STRING
   test_sfinae_with_nasty_char();
+#endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
   test<char>();
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
index b32f6703981af6..1bab0f860d9f34 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/move.pass.cpp
@@ -24,7 +24,6 @@
 #include <spanstream>
 
 #include "constexpr_char_traits.h"
-#include "nasty_string.h"
 #include "test_convertible.h"
 #include "test_macros.h"
 
@@ -47,19 +46,6 @@ struct TestSpanBuf : std::basic_spanbuf<CharT, TraitsT> {
   }
 };
 
-void test_sfinae_with_nasty_char() {
-  using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
-
-  static_assert(std::move_constructible<SpBuf>);
-}
-
-template <typename CharT, typename TraitsT = std::char_traits<CharT>>
-void test_sfinae() {
-  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
-
-  static_assert(std::move_constructible<SpBuf>);
-}
-
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
   using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
@@ -228,9 +214,6 @@ void test() {
 }
 
 int main(int, char**) {
-  test_sfinae_with_nasty_char();
-  test_sfinae<char>();
-  test_sfinae<char, constexpr_char_traits<char>>();
   test<char>();
   test<char, constexpr_char_traits<char>>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
index ff600b92e5c025..fbcc8eeded2595 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
@@ -33,6 +33,7 @@
 #include "../../macros.h"
 #include "../../types.h"
 
+#ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
   using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
 
@@ -44,6 +45,7 @@ void test_sfinae_with_nasty_char() {
   static_assert(!std::constructible_from<SpBuf, const std::span<nasty_char>, const NonMode>);
   static_assert(!test_convertible<SpBuf, const NonMode>());
 }
+#endif // TEST_HAS_NO_NASTY_STRING
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
@@ -171,7 +173,9 @@ void test() {
 }
 
 int main(int, char**) {
+#ifndef TEST_HAS_NO_NASTY_STRING
   test_sfinae_with_nasty_char();
+#endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
   test<char>();
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
index dec47dbf7b8ebc..7ffbb9d24eab90 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/types.compile.pass.cpp
@@ -60,9 +60,11 @@ void test() {
 }
 
 void test() {
+#ifndef TEST_HAS_NO_NASTY_STRING
+  test<nasty_char, nasty_char_traits>();
+#endif
   test<char>();
   test<char, constexpr_char_traits<char>>();
-  test<nasty_char, nasty_char_traits>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test<wchar_t>();
   test<wchar_t, constexpr_char_traits<wchar_t>>();
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
index 7c33c604237a3b..83f6b235ae9135 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/types.compile.pass.cpp
@@ -60,9 +60,11 @@ void test() {
 }
 
 void test() {
+#ifndef TEST_HAS_NO_NASTY_STRING
+  test<nasty_char, nasty_char_traits>();
+#endif
   test<char>();
   test<char, constexpr_char_traits<char>>();
-  test<nasty_char, nasty_char_traits>();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
   test<wchar_t>();
   test<wchar_t, constexpr_char_traits<wchar_t>>();

>From d04d01fcc5ed17c4f27abc1125576bd2ee8bc3cc Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 14:47:23 +0200
Subject: [PATCH 13/29] Implementation: fixes

---
 libcxx/include/spanstream | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index 814fa9a6f00e26..9f048a065c5c05 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -323,7 +323,7 @@ public:
   basic_ospanstream(const basic_ospanstream&) = delete;
 
   _LIBCPP_HIDE_FROM_ABI basic_ospanstream(basic_ospanstream&& __rhs)
-      : basic_ospanstream(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
+      : basic_ostream(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 
@@ -382,7 +382,7 @@ public:
   basic_spanstream(const basic_spanstream&) = delete;
 
   _LIBCPP_HIDE_FROM_ABI basic_spanstream(basic_spanstream&& __rhs)
-      : basic_spanstream(std::move(__rhs)), __sb_(__rhs.__sb_) {
+      : basic_iostream(std::move(__rhs)), __sb_(__rhs.__sb_) {
     basic_iostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 

>From 6e64d59e9ed4277ee8693a655ced64fdef6c5f37 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 15:53:25 +0200
Subject: [PATCH 14/29] Implementation: fixes

---
 libcxx/include/spanstream | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index 9f048a065c5c05..1cad46a2cd1f5c 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -323,7 +323,7 @@ public:
   basic_ospanstream(const basic_ospanstream&) = delete;
 
   _LIBCPP_HIDE_FROM_ABI basic_ospanstream(basic_ospanstream&& __rhs)
-      : basic_ostream(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
+      : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 
@@ -382,7 +382,7 @@ public:
   basic_spanstream(const basic_spanstream&) = delete;
 
   _LIBCPP_HIDE_FROM_ABI basic_spanstream(basic_spanstream&& __rhs)
-      : basic_iostream(std::move(__rhs)), __sb_(__rhs.__sb_) {
+      : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(__rhs.__sb_) {
     basic_iostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 

>From 36644bb003393066c21a44f66e5f7f7aea52175d Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 1 Mar 2024 16:35:45 +0200
Subject: [PATCH 15/29] Tests: `ospanstream` and `spanstream` constructors +
 fixes

---
 libcxx/include/spanstream                     |  14 +-
 .../ospanstream.cons/move.pass.cpp            |  80 ++++++++++
 .../ospanstream.cons/span.mode.pass.cpp       | 140 ++++++++++++++++++
 .../spanstream/spanstream.cons/move.pass.cpp  |  80 ++++++++++
 .../spanstream.cons/span.mode.pass.cpp        | 140 ++++++++++++++++++
 5 files changed, 449 insertions(+), 5 deletions(-)
 create mode 100644 libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/move.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp

diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index 1cad46a2cd1f5c..6a3911a08a0476 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -323,7 +323,7 @@ public:
   basic_ospanstream(const basic_ospanstream&) = delete;
 
   _LIBCPP_HIDE_FROM_ABI basic_ospanstream(basic_ospanstream&& __rhs)
-      : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
+      : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 
@@ -344,9 +344,11 @@ public:
 
   // [ospanstream.members], member functions
 
-  _LIBCPP_HIDE_FROM_ABI basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept { return __sb_; }
+  _LIBCPP_HIDE_FROM_ABI basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept {
+    return const_cast<basic_spanbuf<_CharT, _Traits>*>(std::addressof(__sb_));
+  }
 
-  _LIBCPP_HIDE_FROM_ABI std::span<_CharT> span() const noexcept { return __sb_.rdbuf()->span(); }
+  _LIBCPP_HIDE_FROM_ABI std::span<_CharT> span() const noexcept { return rdbuf()->span(); }
 
   _LIBCPP_HIDE_FROM_ABI void span(std::span<_CharT> __s) noexcept { rdbuf()->span(__s); }
 
@@ -382,7 +384,7 @@ public:
   basic_spanstream(const basic_spanstream&) = delete;
 
   _LIBCPP_HIDE_FROM_ABI basic_spanstream(basic_spanstream&& __rhs)
-      : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(__rhs.__sb_) {
+      : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
     basic_iostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
   }
 
@@ -403,7 +405,9 @@ public:
 
   // [spanstream.members], members
 
-  _LIBCPP_HIDE_FROM_ABI basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept { return __sb_; }
+  _LIBCPP_HIDE_FROM_ABI basic_spanbuf<_CharT, _Traits>* rdbuf() const noexcept {
+    return const_cast<basic_spanbuf<_CharT, _Traits>*>(std::addressof(__sb_));
+  }
 
   _LIBCPP_HIDE_FROM_ABI std::span<_CharT> span() const noexcept { return rdbuf()->span(); }
 
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp
new file mode 100644
index 00000000000000..895e07cdf7ecbd
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ospanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     basic_ospanstream(basic_ospanstream&& rhs);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ospanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream rhsSpStream{sp};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream rhsSpStream{sp, std::ios_base::in};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream rhsSpStream{sp, std::ios_base::out};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream rhsSpStream{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
new file mode 100644
index 00000000000000..086ea7c7653826
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
@@ -0,0 +1,140 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ospanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     explicit basic_ospanstream(std::span<charT> s,
+//                                ios_base::openmode which = ios_base::in);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+#include <utility>
+
+#include "constexpr_char_traits.h"
+#include "nasty_string.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+#include "../../macros.h"
+#include "../../types.h"
+
+#ifndef TEST_HAS_NO_NASTY_STRING
+void test_sfinae_with_nasty_char() {
+  using SpStream = std::basic_ospanstream<nasty_char, nasty_char_traits>;
+
+  // Mode
+  static_assert(std::constructible_from<SpStream, const std::span<nasty_char>, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpStream, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpStream, const std::span<nasty_char>, const NonMode>);
+  static_assert(!test_convertible<SpStream, const std::span<nasty_char>, const NonMode>());
+}
+#endif // TEST_HAS_NO_NASTY_STRING
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test_sfinae() {
+  using SpStream = std::basic_ospanstream<CharT, TraitsT>;
+
+  // Mode
+  static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpStream, const std::span<CharT>, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpStream, const std::span<CharT>, const NonMode>);
+  static_assert(!test_convertible<SpStream, const std::span<CharT>, const NonMode>());
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ospanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream sps(sp);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream sps(sp, std::ios_base::in);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::in);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream sps(sp, std::ios_base::out);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::out);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream sps(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+#ifndef TEST_HAS_NO_NASTY_STRING
+  test_sfinae_with_nasty_char();
+#endif
+  test_sfinae<char>();
+  test_sfinae<char, constexpr_char_traits<char>>();
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test_sfinae<wchar_t>();
+  test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
\ No newline at end of file
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/move.pass.cpp
new file mode 100644
index 00000000000000..1a02487d07198c
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/move.pass.cpp
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     basic_spanstream(basic_spanstream&& rhs);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_spanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream rhsSpStream{sp};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream rhsSpStream{sp, std::ios_base::in};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream rhsSpStream{sp, std::ios_base::out};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream rhsSpStream{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream sps(std::move(rhsSpStream));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
new file mode 100644
index 00000000000000..8fcc216b2ef6b5
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
@@ -0,0 +1,140 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     explicit basic_spanstream(std::span<charT> s,
+//                                ios_base::openmode which = ios_base::in);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+#include <utility>
+
+#include "constexpr_char_traits.h"
+#include "nasty_string.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+#include "../../macros.h"
+#include "../../types.h"
+
+#ifndef TEST_HAS_NO_NASTY_STRING
+void test_sfinae_with_nasty_char() {
+  using SpStream = std::basic_spanstream<nasty_char, nasty_char_traits>;
+
+  // Mode
+  static_assert(std::constructible_from<SpStream, const std::span<nasty_char>, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpStream, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpStream, const std::span<nasty_char>, const NonMode>);
+  static_assert(!test_convertible<SpStream, const std::span<nasty_char>, const NonMode>());
+}
+#endif // TEST_HAS_NO_NASTY_STRING
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test_sfinae() {
+  using SpStream = std::basic_spanstream<CharT, TraitsT>;
+
+  // Mode
+  static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
+  static_assert(!test_convertible<SpStream, const std::span<CharT>, std::ios_base::openmode>());
+
+  // Non-mode
+  static_assert(!std::constructible_from<SpStream, const std::span<CharT>, const NonMode>);
+  static_assert(!test_convertible<SpStream, const std::span<CharT>, const NonMode>());
+}
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_spanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream sps(sp);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp));
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream sps(sp, std::ios_base::in);
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::in);
+    assert(sps.span().data() == arr);
+    assert(!sps.span().empty());
+    assert(sps.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream sps(sp, std::ios_base::out);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::out);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream sps(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+  {
+    SpStream sps(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(sps.span().data() == arr);
+    assert(sps.span().empty());
+    assert(sps.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+#ifndef TEST_HAS_NO_NASTY_STRING
+  test_sfinae_with_nasty_char();
+#endif
+  test_sfinae<char>();
+  test_sfinae<char, constexpr_char_traits<char>>();
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test_sfinae<wchar_t>();
+  test_sfinae<wchar_t, constexpr_char_traits<wchar_t>>();
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
\ No newline at end of file

>From 6781770705878acb845ea1e2a9116ea348cf8f0d Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sat, 2 Mar 2024 08:26:39 +0200
Subject: [PATCH 16/29] Tests: `ispanstream` added assign and swap

---
 libcxx/include/spanstream                     | 45 ++++++----
 .../ispanstream.assign/move.pass.cpp          | 80 ++++++++++++++++++
 .../ispanstream.assign/swap.pass.cpp          | 83 +++++++++++++++++++
 .../swap_nonmember.pass.cpp                   | 79 ++++++++++++++++++
 .../ispanstream.cons/move.pass.cpp            | 40 ++++-----
 .../ispanstream.cons/span.mode.pass.cpp       | 64 +++++++-------
 .../ospanstream.cons/move.pass.cpp            | 40 ++++-----
 .../ospanstream.cons/span.mode.pass.cpp       | 64 +++++++-------
 .../spanstream/spanstream.cons/move.pass.cpp  | 40 ++++-----
 .../spanstream.cons/span.mode.pass.cpp        | 64 +++++++-------
 10 files changed, 427 insertions(+), 172 deletions(-)
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/move.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap_nonmember.pass.cpp

diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index 6a3911a08a0476..70e6faa4206fbe 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -167,24 +167,37 @@ protected:
     if ((__which & ios_base::in) && (__which & ios_base::out) && (ios_base::cur == __way))
       return __error;
 
-    off_type __baseoff = [this, __way, __which] {
-      switch (__way) {
-      case ios_base::beg:
-        return off_type(0);
-
-      case ios_base::cur:
-        if (__which & ios_base::out)
-          return off_type(this->pptr() - this->pbase());
-        return off_type(this->gptr() - this->eback());
-
-      case ios_base::end:
-        if ((__which & ios_base::out) && !(__which & ios_base::in))
-          return off_type(this->pptr() - this->pbase());
-        return off_type(__buf_.size());
-      }
-    }();
+    // Calculate __baseoff
+
+    off_type __baseoff;
+
+    switch (__way) {
+    case ios_base::beg:
+      __baseoff = off_type(0);
+      break;
+
+    case ios_base::cur:
+      if (__which & ios_base::out)
+        __baseoff = off_type(this->pptr() - this->pbase());
+      else
+        __baseoff = off_type(this->gptr() - this->eback());
+      break;
+
+    case ios_base::end:
+      if ((__which & ios_base::out) && !(__which & ios_base::in))
+        __baseoff = off_type(this->pptr() - this->pbase());
+      else
+        __baseoff = off_type(__buf_.size());
+      break;
+
+    default:
+      return __error;
+    };
+
+    // Calculate __newoff
 
     off_type __newoff;
+
     if (__builtin_add_overflow(__baseoff, __off, &__newoff) || (__newoff < off_type(0)) ||
         (std::cmp_greater(__newoff, __buf_.size())))
       return __error;
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/move.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/move.pass.cpp
new file mode 100644
index 00000000000000..117e2a6828e9da
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/move.pass.cpp
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ispanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     basic_ispanstream& operator=(basic_ispanstream&& rhs);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream rhsSpSt{sp};
+    SpStream spSt = std::move(rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream rhsSpSt{sp, std::ios_base::in};
+    SpStream spSt = std::move(rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream rhsSpSt{sp, std::ios_base::out};
+    SpStream spSt = std::move(rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream rhsSpSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream spSt = std::move(rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap.pass.cpp
new file mode 100644
index 00000000000000..45fc6370a06d40
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap.pass.cpp
@@ -0,0 +1,83 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_ispanstream
+//     : public basic_streambuf<charT, traits> {
+
+//     // [ispanstream.swap], swap
+//     void swap(basic_ispanstream& rhs);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream rhsSpSt{sp};
+    SpStream spSt(std::span<CharT>{});
+    spSt.swap(rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream rhsSpSt{sp, std::ios_base::in};
+    SpStream spSt(std::span<CharT>{});
+    spSt.swap(rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream rhsSpSt{sp, std::ios_base::out};
+    SpStream spSt(std::span<CharT>{});
+    spSt.swap(rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream rhsSpSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream spSt(std::span<CharT>{});
+    spSt.swap(rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap_nonmember.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap_nonmember.pass.cpp
new file mode 100644
index 00000000000000..ae54e409297454
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap_nonmember.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits>
+//     void swap(basic_ispanstream<charT, traits>& x, basic_ispanstream<charT, traits>& y);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpStream rhsSpSt{sp};
+    SpStream spSt(std::span<CharT>{});
+    std::swap(spSt, rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpStream rhsSpSt{sp, std::ios_base::in};
+    SpStream spSt(std::span<CharT>{});
+    std::swap(spSt, rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpStream rhsSpSt{sp, std::ios_base::out};
+    SpStream spSt(std::span<CharT>{});
+    std::swap(spSt, rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpStream rhsSpSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream spSt(std::span<CharT>{});
+    std::swap(spSt, rhsSpSt);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
index 1b456a8a0ef38b..2207b773bd9cef 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/move.pass.cpp
@@ -36,35 +36,35 @@ void test() {
 
   // Mode: default
   {
-    SpStream rhsSpStream{sp};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream rhsSpSt{sp};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   // Mode: `ios_base::in`
   {
-    SpStream rhsSpStream{sp, std::ios_base::in};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream rhsSpSt{sp, std::ios_base::in};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   // Mode `ios_base::out`
   {
-    SpStream rhsSpStream{sp, std::ios_base::out};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp, std::ios_base::out};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: multiple
   {
-    SpStream rhsSpStream{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
 }
 
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
index cd793210e2c063..3502bbc1d676d7 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
@@ -69,55 +69,55 @@ void test() {
 
   // Mode: default
   {
-    SpStream sps(sp);
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream spSt(sp);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   {
-    SpStream sps(std::as_const(sp));
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream spSt(std::as_const(sp));
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   // Mode: `ios_base::in`
   {
-    SpStream sps(sp, std::ios_base::in);
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream spSt(sp, std::ios_base::in);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::in);
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream spSt(std::as_const(sp), std::ios_base::in);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   // Mode `ios_base::out`
   {
-    SpStream sps(sp, std::ios_base::out);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp, std::ios_base::out);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::out);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp), std::ios_base::out);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: multiple
   {
-    SpStream sps(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
 }
 
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp
index 895e07cdf7ecbd..43354d6b8dfcba 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/move.pass.cpp
@@ -36,35 +36,35 @@ void test() {
 
   // Mode: default
   {
-    SpStream rhsSpStream{sp};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: `ios_base::in`
   {
-    SpStream rhsSpStream{sp, std::ios_base::in};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp, std::ios_base::in};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode `ios_base::out`
   {
-    SpStream rhsSpStream{sp, std::ios_base::out};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp, std::ios_base::out};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: multiple
   {
-    SpStream rhsSpStream{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
 }
 
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
index 086ea7c7653826..f353719875bc96 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
@@ -69,55 +69,55 @@ void test() {
 
   // Mode: default
   {
-    SpStream sps(sp);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: `ios_base::in`
   {
-    SpStream sps(sp, std::ios_base::in);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp, std::ios_base::in);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::in);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp), std::ios_base::in);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode `ios_base::out`
   {
-    SpStream sps(sp, std::ios_base::out);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp, std::ios_base::out);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::out);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp), std::ios_base::out);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: multiple
   {
-    SpStream sps(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
 }
 
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/move.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/move.pass.cpp
index 1a02487d07198c..73206597cd27d5 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/move.pass.cpp
@@ -36,35 +36,35 @@ void test() {
 
   // Mode: default
   {
-    SpStream rhsSpStream{sp};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: `ios_base::in`
   {
-    SpStream rhsSpStream{sp, std::ios_base::in};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream rhsSpSt{sp, std::ios_base::in};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   // Mode `ios_base::out`
   {
-    SpStream rhsSpStream{sp, std::ios_base::out};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp, std::ios_base::out};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: multiple
   {
-    SpStream rhsSpStream{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
-    SpStream sps(std::move(rhsSpStream));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream rhsSpSt{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpStream spSt(std::move(rhsSpSt));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
 }
 
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
index 8fcc216b2ef6b5..61a1a2530ad754 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
@@ -69,55 +69,55 @@ void test() {
 
   // Mode: default
   {
-    SpStream sps(sp);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp));
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp));
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: `ios_base::in`
   {
-    SpStream sps(sp, std::ios_base::in);
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream spSt(sp, std::ios_base::in);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::in);
-    assert(sps.span().data() == arr);
-    assert(!sps.span().empty());
-    assert(sps.span().size() == 4);
+    SpStream spSt(std::as_const(sp), std::ios_base::in);
+    assert(spSt.span().data() == arr);
+    assert(!spSt.span().empty());
+    assert(spSt.span().size() == 4);
   }
   // Mode `ios_base::out`
   {
-    SpStream sps(sp, std::ios_base::out);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp, std::ios_base::out);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::out);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp), std::ios_base::out);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   // Mode: multiple
   {
-    SpStream sps(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
   {
-    SpStream sps(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
-    assert(sps.span().data() == arr);
-    assert(sps.span().empty());
-    assert(sps.span().size() == 0);
+    SpStream spSt(std::as_const(sp), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
   }
 }
 

>From 645c964a206e25b31511ebb1fb6b55509da8321d Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 3 Mar 2024 18:08:43 +0200
Subject: [PATCH 17/29] Tests: added `ReadonlySpan` type

---
 .../ispanstream/ispanstream.cons/ros.pass.cpp |   2 +
 .../std/input.output/span.streams/types.h     | 230 +++++++++++++++---
 2 files changed, 193 insertions(+), 39 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
index 421ba8ff10e169..017cf24a89d7b4 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
@@ -25,6 +25,8 @@
 #include "nasty_string.h"
 #include "test_macros.h"
 
+#include "../../types.h"
+
 #ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
   using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
diff --git a/libcxx/test/std/input.output/span.streams/types.h b/libcxx/test/std/input.output/span.streams/types.h
index 18788a56579dcb..0d8eecd5f4db0c 100644
--- a/libcxx/test/std/input.output/span.streams/types.h
+++ b/libcxx/test/std/input.output/span.streams/types.h
@@ -9,62 +9,214 @@
 #ifndef TEST_STD_INPUTOUTPUT_SPANSTREAMS_TYPES_H
 #define TEST_STD_INPUTOUTPUT_SPANSTREAMS_TYPES_H
 
-#include <string_view>
 #include <concepts>
+#include <cstddef>
+#include <span>
+#include <ranges>
 
 #include "test_macros.h"
 
-// template <typename CharT, class Traits = std::char_traits<CharT>>
-// class ConstConvertibleStringView {
-// public:
-//   explicit ConstConvertibleStringView(const CharT* cs) : cs_{cs} {}
+template <typename CharT, std::size_t N = 0>
+class ReadOnlySpan {
+  explicit ReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
 
-//   operator std::basic_string_view<CharT, Traits>() = delete;
-//   operator std::basic_string_view<CharT, Traits>() const { return std::basic_string_view<CharT, Traits>(cs_); }
+public:
+  operator std::span<CharT>() = delete;
 
-// private:
-//   const CharT* cs_;
-// };
+  operator std::span<const CharT>() { return std::span<const CharT, N>{arr_}; }
 
-// static_assert(!std::constructible_from<std::basic_string_view<char>, ConstConvertibleStringView<char>>);
-// static_assert(!std::convertible_to<ConstConvertibleStringView<char>, std::basic_string_view<char>>);
+  const CharT* begin() { return arr_; }
+  const CharT* end() { return arr_ + N; }
 
-// static_assert(std::constructible_from<std::basic_string_view<char>, const ConstConvertibleStringView<char>>);
-// static_assert(std::convertible_to<const ConstConvertibleStringView<char>, std::basic_string_view<char>>);
+private:
+  CharT* arr_;
+};
 
-// #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-// static_assert(!std::constructible_from<std::basic_string_view<wchar_t>, ConstConvertibleStringView<wchar_t>>);
-// static_assert(!std::convertible_to<ConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>);
+template <typename CharT, std::size_t N>
+inline constexpr bool std::ranges::enable_borrowed_range<ReadOnlySpan<CharT, N>> = true;
 
-// static_assert(std::constructible_from<std::basic_string_view<wchar_t>, const ConstConvertibleStringView<wchar_t>>);
-// static_assert(std::convertible_to<const ConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>);
-// #endif
+static_assert(std::ranges::borrowed_range<ReadOnlySpan<char>>);
 
-// template <typename CharT, class Traits = std::char_traits<CharT>>
-// class NonConstConvertibleStringView {
-// public:
-//   explicit NonConstConvertibleStringView(const CharT* cs) : cs_{cs} {}
+static_assert(!std::constructible_from<std::span<char>, ReadOnlySpan<char>>);
+static_assert(!std::convertible_to<ReadOnlySpan<char>, std::span<char>>);
 
-//   operator std::basic_string_view<CharT, Traits>() { return std::basic_string_view<CharT, Traits>(cs_); }
-//   operator std::basic_string_view<CharT, Traits>() const = delete;
+static_assert(!std::constructible_from<std::span<char>, const ReadOnlySpan<char>>);
+static_assert(!std::convertible_to<const ReadOnlySpan<char>, std::span<char>>);
 
-// private:
-//   const CharT* cs_;
-// };
+static_assert(std::constructible_from<std::span<const char>, ReadOnlySpan<char>>);
+static_assert(std::convertible_to<ReadOnlySpan<char>, std::span<const char>>);
 
-// static_assert(std::constructible_from<std::basic_string_view<char>, NonConstConvertibleStringView<char>>);
-// static_assert(std::convertible_to<NonConstConvertibleStringView<char>, std::basic_string_view<char>>);
+static_assert(!std::constructible_from<std::span<const char>, const ReadOnlySpan<char>>);
+static_assert(!std::convertible_to<const ReadOnlySpan<char>, std::span<const char>>);
 
-// static_assert(!std::constructible_from<std::basic_string_view<char>, const NonConstConvertibleStringView<char>>);
-// static_assert(!std::convertible_to<const NonConstConvertibleStringView<char>, std::basic_string_view<char>>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
 
-// #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-// static_assert(std::constructible_from<std::basic_string_view<wchar_t>, NonConstConvertibleStringView<wchar_t>>);
-// static_assert(std::convertible_to<NonConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>);
+static_assert(std::ranges::borrowed_range<ReadOnlySpan<wchar_t>>);
 
-// static_assert(!std::constructible_from<std::basic_string_view<wchar_t>, const NonConstConvertibleStringView<wchar_t>>);
-// static_assert(!std::convertible_to<const NonConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>);
-// #endif
+static_assert(!std::constructible_from<std::span<wchar_t>, ReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<ReadOnlySpan<wchar_t>, std::span<wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<wchar_t>, const ReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<const ReadOnlySpan<wchar_t>, std::span<wchar_t>>);
+
+static_assert(std::constructible_from<std::span<const wchar_t>, ReadOnlySpan<wchar_t>>);
+static_assert(std::convertible_to<ReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<const wchar_t>, const ReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<const ReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
+#endif
+
+template <typename CharT, std::size_t N = 0>
+class NonReadOnlySpan {
+  explicit NonReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
+
+public:
+  operator std::span<CharT>() { return std::span<CharT, N>{arr_}; }
+
+  operator std::span<const CharT>() = delete;
+
+  CharT* begin() { return arr_; }
+  CharT* end() { return arr_ + N; }
+
+private:
+  CharT* arr_;
+};
+
+template <typename CharT, std::size_t N>
+inline constexpr bool std::ranges::enable_borrowed_range<NonReadOnlySpan<CharT, N>> = true;
+
+static_assert(std::ranges::borrowed_range<NonReadOnlySpan<char>>);
+
+static_assert(std::constructible_from<std::span<char>, NonReadOnlySpan<char>>);
+static_assert(std::convertible_to<NonReadOnlySpan<char>, std::span<char>>);
+
+static_assert(!std::constructible_from<std::span<char>, const NonReadOnlySpan<char>>);
+static_assert(!std::convertible_to<const NonReadOnlySpan<char>, std::span<char>>);
+
+static_assert(std::constructible_from<std::span<const char>, NonReadOnlySpan<char>>);
+static_assert(!std::convertible_to<NonReadOnlySpan<char>, std::span<const char>>);
+
+static_assert(!std::constructible_from<std::span<const char>, const NonReadOnlySpan<char>>);
+static_assert(!std::convertible_to<const NonReadOnlySpan<char>, std::span<const char>>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::ranges::borrowed_range<NonReadOnlySpan<wchar_t>>);
+
+static_assert(std::constructible_from<std::span<wchar_t>, NonReadOnlySpan<wchar_t>>);
+static_assert(std::convertible_to<NonReadOnlySpan<wchar_t>, std::span<wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<wchar_t>, const NonReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<const NonReadOnlySpan<wchar_t>, std::span<wchar_t>>);
+
+static_assert(std::constructible_from<std::span<const wchar_t>, NonReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<NonReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<const wchar_t>, const NonReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<const NonReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
+#endif
+
+template <typename CharT, std::size_t N = 0>
+class ConstConvertibleReadOnlySpan {
+  explicit ConstConvertibleReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
+
+public:
+  operator std::span<CharT>()       = delete;
+  operator std::span<CharT>() const = delete;
+
+  operator std::span<const CharT>() = delete;
+  operator std::span<const CharT>() const { return std::span<const CharT, N>{arr_}; }
+
+  const CharT* begin() { return arr_; }
+  const CharT* end() { return arr_ + N; }
+
+private:
+  CharT* arr_;
+};
+
+template <typename CharT, std::size_t N>
+inline constexpr bool std::ranges::enable_borrowed_range<ConstConvertibleReadOnlySpan<CharT, N>> = true;
+
+static_assert(std::ranges::borrowed_range<ConstConvertibleReadOnlySpan<char>>);
+
+static_assert(!std::constructible_from<std::span<char>, ConstConvertibleReadOnlySpan<char>>);
+static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<char>, std::span<char>>);
+
+static_assert(!std::constructible_from<std::span<char>, const ConstConvertibleReadOnlySpan<char>>);
+static_assert(!std::convertible_to<const ConstConvertibleReadOnlySpan<char>, std::span<char>>);
+
+static_assert(std::constructible_from<std::span<const char>, ConstConvertibleReadOnlySpan<char>>);
+static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<char>, std::span<const char>>);
+
+static_assert(std::constructible_from<std::span<const char>, const ConstConvertibleReadOnlySpan<char>>);
+static_assert(std::convertible_to<const ConstConvertibleReadOnlySpan<char>, std::span<const char>>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+
+static_assert(std::ranges::borrowed_range<ConstConvertibleReadOnlySpan<wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<wchar_t>, ConstConvertibleReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<wchar_t>, const ConstConvertibleReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<const ConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>);
+
+static_assert(std::constructible_from<std::span<const wchar_t>, ConstConvertibleReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
+
+static_assert(std::constructible_from<std::span<const wchar_t>, const ConstConvertibleReadOnlySpan<wchar_t>>);
+static_assert(std::convertible_to<const ConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
+#endif
+
+template <typename CharT, std::size_t N = 0>
+class NonConstConvertibleReadOnlySpan {
+  explicit NonConstConvertibleReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
+
+public:
+  operator std::span<CharT>()       = delete;
+  operator std::span<CharT>() const = delete;
+
+  operator std::span<const CharT>() { return std::span<const CharT, N>{arr_}; }
+  operator std::span<const CharT>() const = delete;
+
+  const CharT* begin() { return arr_; }
+  const CharT* end() { return arr_ + N; }
+
+private:
+  CharT* arr_;
+};
+
+template <typename CharT, std::size_t N>
+inline constexpr bool std::ranges::enable_borrowed_range<NonConstConvertibleReadOnlySpan<CharT, N>> = true;
+
+static_assert(std::ranges::borrowed_range<NonConstConvertibleReadOnlySpan<char>>);
+
+static_assert(!std::constructible_from<std::span<char>, NonConstConvertibleReadOnlySpan<char>>);
+static_assert(!std::convertible_to<NonConstConvertibleReadOnlySpan<char>, std::span<char>>);
+
+static_assert(!std::constructible_from<std::span<char>, const NonConstConvertibleReadOnlySpan<char>>);
+static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<char>, std::span<char>>);
+
+static_assert(std::constructible_from<std::span<const char>, NonConstConvertibleReadOnlySpan<char>>);
+static_assert(std::convertible_to<NonConstConvertibleReadOnlySpan<char>, std::span<const char>>);
+
+static_assert(!std::constructible_from<std::span<const char>, const NonConstConvertibleReadOnlySpan<char>>);
+static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<char>, std::span<const char>>);
+
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(std::ranges::borrowed_range<NonConstConvertibleReadOnlySpan<wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<wchar_t>, NonConstConvertibleReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<NonConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<wchar_t>, const NonConstConvertibleReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>);
+
+static_assert(std::constructible_from<std::span<const wchar_t>, NonConstConvertibleReadOnlySpan<wchar_t>>);
+static_assert(std::convertible_to<NonConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
+
+static_assert(!std::constructible_from<std::span<const wchar_t>, const NonConstConvertibleReadOnlySpan<wchar_t>>);
+static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
+#endif
 
 struct SomeObject {};
 

>From 7b40e2e24d4b81bf4e3289106046bef49e4c1c45 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Mon, 4 Mar 2024 07:42:41 +0200
Subject: [PATCH 18/29] Tests: WIP `ROS` constructor

---
 libcxx/include/spanstream                     |  7 +++
 .../{macros.h => helper_macros.h}             |  0
 .../span.streams/{types.h => helper_types.h}  | 21 +++++--
 .../ispanstream/ispanstream.cons/ros.pass.cpp | 62 +++++++++++++++++--
 .../ispanstream.cons/span.mode.pass.cpp       |  4 +-
 .../input.output/span.streams/lit.local.cfg   |  3 +
 .../ospanstream.cons/span.mode.pass.cpp       |  4 +-
 .../spanbuf/spanbuf.cons/mode.pass.cpp        |  2 +-
 .../spanbuf/spanbuf.cons/span.mode.pass.cpp   |  4 +-
 .../spanstream.cons/span.mode.pass.cpp        |  4 +-
 10 files changed, 93 insertions(+), 18 deletions(-)
 rename libcxx/test/std/input.output/span.streams/{macros.h => helper_macros.h} (100%)
 rename libcxx/test/std/input.output/span.streams/{types.h => helper_types.h} (96%)
 create mode 100644 libcxx/test/std/input.output/span.streams/lit.local.cfg

diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index 70e6faa4206fbe..14fd39d93e9915 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -66,6 +66,7 @@
 #include <__utility/move.h>
 #include <__utility/swap.h>
 #include <iostream>
+#include <print>
 #include <span>
 #include <streambuf>
 #include <version>
@@ -266,8 +267,14 @@ public:
     requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
   _LIBCPP_HIDE_FROM_ABI explicit basic_ispanstream(_ROSeq&& __s)
       : basic_istream<_CharT, _Traits>(std::addressof(__sb_)) {
+    std::println(stderr, "ispanstream");
     std::span<const _CharT> __sp(std::forward<_ROSeq>(__s));
+    std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
+    std::println(stderr, "span data {} {}", __sp.empty(), __sp.size());
+    std::println(stderr, "ispanstream 2");
     this->span(std::span<_CharT>(std::span<_CharT>(const_cast<_CharT*>(__sp.data()), __sp.size())));
+    std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
+    std::println(stderr, "ispanstream 3");
   }
 
   basic_ispanstream& operator=(const basic_ispanstream&) = delete;
diff --git a/libcxx/test/std/input.output/span.streams/macros.h b/libcxx/test/std/input.output/span.streams/helper_macros.h
similarity index 100%
rename from libcxx/test/std/input.output/span.streams/macros.h
rename to libcxx/test/std/input.output/span.streams/helper_macros.h
diff --git a/libcxx/test/std/input.output/span.streams/types.h b/libcxx/test/std/input.output/span.streams/helper_types.h
similarity index 96%
rename from libcxx/test/std/input.output/span.streams/types.h
rename to libcxx/test/std/input.output/span.streams/helper_types.h
index 0d8eecd5f4db0c..81fb2c7557714c 100644
--- a/libcxx/test/std/input.output/span.streams/types.h
+++ b/libcxx/test/std/input.output/span.streams/helper_types.h
@@ -16,17 +16,28 @@
 
 #include "test_macros.h"
 
+#include <print>
+
 template <typename CharT, std::size_t N = 0>
 class ReadOnlySpan {
+public:
   explicit ReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
 
-public:
   operator std::span<CharT>() = delete;
 
-  operator std::span<const CharT>() { return std::span<const CharT, N>{arr_}; }
+  operator std::span<const CharT>() {
+    std::println(stderr, "----> ROspan");
+    return std::span<const CharT, N>{arr_};
+  }
 
-  const CharT* begin() { return arr_; }
-  const CharT* end() { return arr_ + N; }
+  const CharT* begin() {
+    std::println(stderr, "----> ROspan begin");
+    return arr_;
+  }
+  const CharT* end() {
+    std::println(stderr, "----> ROspan end");
+    return arr_ + N;
+  }
 
 private:
   CharT* arr_;
@@ -68,9 +79,9 @@ static_assert(!std::convertible_to<const ReadOnlySpan<wchar_t>, std::span<const
 
 template <typename CharT, std::size_t N = 0>
 class NonReadOnlySpan {
+public:
   explicit NonReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
 
-public:
   operator std::span<CharT>() { return std::span<CharT, N>{arr_}; }
 
   operator std::span<const CharT>() = delete;
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
index 017cf24a89d7b4..7a4f0f422404f4 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
@@ -19,27 +19,60 @@
 //     template<class ROS> explicit basic_ispanstream(ROS&& s);
 
 #include <cassert>
+#include <concepts>
 #include <spanstream>
 
 #include "constexpr_char_traits.h"
 #include "nasty_string.h"
+#include "test_convertible.h"
 #include "test_macros.h"
 
-#include "../../types.h"
+#include "../../helper_types.h"
 
 #ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
   using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
 
-  // TODO:
+  // Non-const convertible
+  static_assert(std::constructible_from<SpStream, ReadOnlySpan<nasty_char>>);
+  static_assert(!test_convertible<SpStream, ReadOnlySpan<nasty_char>>());
+
+  // Const convertible
+  static_assert(!std::constructible_from<SpStream, const ReadOnlySpan<nasty_char>>);
+  static_assert(!test_convertible<SpStream, const ReadOnlySpan<nasty_char>>());
+
+  // Non-const non-convertible
+  static_assert(std::constructible_from<SpStream, ReadOnlySpan<nasty_char>>);
+  static_assert(!test_convertible<SpStream, ReadOnlySpan<nasty_char>>());
+
+  // Const non-convertible
+  static_assert(!std::constructible_from<SpStream, const ReadOnlySpan<nasty_char>>);
+  static_assert(!test_convertible<SpStream, const ReadOnlySpan<nasty_char>>());
 }
 #endif // TEST_HAS_NO_NASTY_STRING
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
-  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
+  using SpStream =
+      std::conditional_t<std::same_as<CharT, nasty_char>,
+                         std::basic_ispanstream<nasty_char, nasty_char_traits>,
+                         std::basic_ispanstream<CharT, TraitsT>>;
 
-  // TODO:
+  // Non-const convertible
+  static_assert(std::constructible_from<SpStream, ReadOnlySpan<CharT>>);
+  static_assert(!test_convertible<SpStream, ReadOnlySpan<CharT>>());
+
+  // Const convertible
+  static_assert(!std::constructible_from<SpStream, const ReadOnlySpan<CharT>>);
+  static_assert(!test_convertible<SpStream, const ReadOnlySpan<CharT>>());
+
+  // Non-const non-convertible
+  static_assert(std::constructible_from<SpStream, NonReadOnlySpan<CharT>>);
+  static_assert(!test_convertible<SpStream, NonReadOnlySpan<CharT>>());
+
+  // Const non-convertible
+  static_assert(!std::constructible_from<SpStream, const NonReadOnlySpan<CharT>>);
+  static_assert(!test_convertible<SpStream, const NonReadOnlySpan<CharT>>());
 }
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
@@ -47,10 +80,31 @@ void test() {
   using SpStream = std::basic_ispanstream<CharT, TraitsT>;
 
   // TODO:
+  CharT arr[4];
+  ReadOnlySpan<CharT, 4> ros{arr};
+
+  {
+    SpStream spSt(ros);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
+  }
+
+  CharT arr1[6];
+  ReadOnlySpan<CharT, 6> ros2{arr1};
+
+  {
+    SpStream spSt(ros2);
+    assert(spSt.span().data() == arr);
+    assert(spSt.span().data() == arr1);
+    assert(spSt.span().empty());
+    assert(spSt.span().size() == 0);
+  }
 }
 
 int main(int, char**) {
 #ifndef TEST_HAS_NO_NASTY_STRING
+  // test_sfinae<nasty_char, nasty_char_traits>();
   test_sfinae_with_nasty_char();
 #endif
   test_sfinae<char>();
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
index 3502bbc1d676d7..3527d197e7cdf9 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
@@ -30,8 +30,8 @@
 #include "test_convertible.h"
 #include "test_macros.h"
 
-#include "../../macros.h"
-#include "../../types.h"
+#include "../../helper_macros.h"
+#include "../../helper_types.h"
 
 #ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
diff --git a/libcxx/test/std/input.output/span.streams/lit.local.cfg b/libcxx/test/std/input.output/span.streams/lit.local.cfg
new file mode 100644
index 00000000000000..2cb10010c45072
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/lit.local.cfg
@@ -0,0 +1,3 @@
+# All non-trivial uses of iostreams require localization support
+if "no-localization" in config.available_features:
+    config.unsupported = True
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
index f353719875bc96..e036a0be4a48ba 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
@@ -30,8 +30,8 @@
 #include "test_convertible.h"
 #include "test_macros.h"
 
-#include "../../macros.h"
-#include "../../types.h"
+#include "../../helper_macros.h"
+#include "../../helper_types.h"
 
 #ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
index eb8b29de9fbff0..d040f0beb92a55 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
@@ -28,7 +28,7 @@
 #include "test_convertible.h"
 #include "test_macros.h"
 
-#include "../../types.h"
+#include "../../helper_types.h"
 
 #ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
index fbcc8eeded2595..45985aed49c618 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
@@ -30,8 +30,8 @@
 #include "test_convertible.h"
 #include "test_macros.h"
 
-#include "../../macros.h"
-#include "../../types.h"
+#include "../../helper_macros.h"
+#include "../../helper_types.h"
 
 #ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
index 61a1a2530ad754..2423c92fda9f8b 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
@@ -30,8 +30,8 @@
 #include "test_convertible.h"
 #include "test_macros.h"
 
-#include "../../macros.h"
-#include "../../types.h"
+#include "../../helper_macros.h"
+#include "../../helper_types.h"
 
 #ifndef TEST_HAS_NO_NASTY_STRING
 void test_sfinae_with_nasty_char() {

>From cb3b9cf091a1e9b791061869d7ed8ab7e84d1c22 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Mon, 4 Mar 2024 07:47:34 +0200
Subject: [PATCH 19/29] Tests: WIP retry CI

---
 libcxx/include/spanstream                     |  14 +--
 .../input.output/span.streams/helper_types.h  | 111 +-----------------
 .../ispanstream/ispanstream.cons/ros.pass.cpp |  27 +----
 3 files changed, 13 insertions(+), 139 deletions(-)

diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index 14fd39d93e9915..c735baaae93d90 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -66,7 +66,7 @@
 #include <__utility/move.h>
 #include <__utility/swap.h>
 #include <iostream>
-#include <print>
+// #include <print>
 #include <span>
 #include <streambuf>
 #include <version>
@@ -267,14 +267,14 @@ public:
     requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
   _LIBCPP_HIDE_FROM_ABI explicit basic_ispanstream(_ROSeq&& __s)
       : basic_istream<_CharT, _Traits>(std::addressof(__sb_)) {
-    std::println(stderr, "ispanstream");
+    // std::println(stderr, "ispanstream");
     std::span<const _CharT> __sp(std::forward<_ROSeq>(__s));
-    std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
-    std::println(stderr, "span data {} {}", __sp.empty(), __sp.size());
-    std::println(stderr, "ispanstream 2");
+    // std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
+    // std::println(stderr, "span data {} {}", __sp.empty(), __sp.size());
+    // std::println(stderr, "ispanstream 2");
     this->span(std::span<_CharT>(std::span<_CharT>(const_cast<_CharT*>(__sp.data()), __sp.size())));
-    std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
-    std::println(stderr, "ispanstream 3");
+    // std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
+    // std::println(stderr, "ispanstream 3");
   }
 
   basic_ispanstream& operator=(const basic_ispanstream&) = delete;
diff --git a/libcxx/test/std/input.output/span.streams/helper_types.h b/libcxx/test/std/input.output/span.streams/helper_types.h
index 81fb2c7557714c..7f67432f9f8806 100644
--- a/libcxx/test/std/input.output/span.streams/helper_types.h
+++ b/libcxx/test/std/input.output/span.streams/helper_types.h
@@ -16,7 +16,7 @@
 
 #include "test_macros.h"
 
-#include <print>
+// #include <print>
 
 template <typename CharT, std::size_t N = 0>
 class ReadOnlySpan {
@@ -26,16 +26,16 @@ class ReadOnlySpan {
   operator std::span<CharT>() = delete;
 
   operator std::span<const CharT>() {
-    std::println(stderr, "----> ROspan");
+    // std::println(stderr, "----> ROspan");
     return std::span<const CharT, N>{arr_};
   }
 
   const CharT* begin() {
-    std::println(stderr, "----> ROspan begin");
+    // std::println(stderr, "----> ROspan begin");
     return arr_;
   }
   const CharT* end() {
-    std::println(stderr, "----> ROspan end");
+    // std::println(stderr, "----> ROspan end");
     return arr_ + N;
   }
 
@@ -126,109 +126,6 @@ static_assert(!std::constructible_from<std::span<const wchar_t>, const NonReadOn
 static_assert(!std::convertible_to<const NonReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
 #endif
 
-template <typename CharT, std::size_t N = 0>
-class ConstConvertibleReadOnlySpan {
-  explicit ConstConvertibleReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
-
-public:
-  operator std::span<CharT>()       = delete;
-  operator std::span<CharT>() const = delete;
-
-  operator std::span<const CharT>() = delete;
-  operator std::span<const CharT>() const { return std::span<const CharT, N>{arr_}; }
-
-  const CharT* begin() { return arr_; }
-  const CharT* end() { return arr_ + N; }
-
-private:
-  CharT* arr_;
-};
-
-template <typename CharT, std::size_t N>
-inline constexpr bool std::ranges::enable_borrowed_range<ConstConvertibleReadOnlySpan<CharT, N>> = true;
-
-static_assert(std::ranges::borrowed_range<ConstConvertibleReadOnlySpan<char>>);
-
-static_assert(!std::constructible_from<std::span<char>, ConstConvertibleReadOnlySpan<char>>);
-static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<char>, std::span<char>>);
-
-static_assert(!std::constructible_from<std::span<char>, const ConstConvertibleReadOnlySpan<char>>);
-static_assert(!std::convertible_to<const ConstConvertibleReadOnlySpan<char>, std::span<char>>);
-
-static_assert(std::constructible_from<std::span<const char>, ConstConvertibleReadOnlySpan<char>>);
-static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<char>, std::span<const char>>);
-
-static_assert(std::constructible_from<std::span<const char>, const ConstConvertibleReadOnlySpan<char>>);
-static_assert(std::convertible_to<const ConstConvertibleReadOnlySpan<char>, std::span<const char>>);
-
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-
-static_assert(std::ranges::borrowed_range<ConstConvertibleReadOnlySpan<wchar_t>>);
-
-static_assert(!std::constructible_from<std::span<wchar_t>, ConstConvertibleReadOnlySpan<wchar_t>>);
-static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>);
-
-static_assert(!std::constructible_from<std::span<wchar_t>, const ConstConvertibleReadOnlySpan<wchar_t>>);
-static_assert(!std::convertible_to<const ConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>);
-
-static_assert(std::constructible_from<std::span<const wchar_t>, ConstConvertibleReadOnlySpan<wchar_t>>);
-static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
-
-static_assert(std::constructible_from<std::span<const wchar_t>, const ConstConvertibleReadOnlySpan<wchar_t>>);
-static_assert(std::convertible_to<const ConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
-#endif
-
-template <typename CharT, std::size_t N = 0>
-class NonConstConvertibleReadOnlySpan {
-  explicit NonConstConvertibleReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
-
-public:
-  operator std::span<CharT>()       = delete;
-  operator std::span<CharT>() const = delete;
-
-  operator std::span<const CharT>() { return std::span<const CharT, N>{arr_}; }
-  operator std::span<const CharT>() const = delete;
-
-  const CharT* begin() { return arr_; }
-  const CharT* end() { return arr_ + N; }
-
-private:
-  CharT* arr_;
-};
-
-template <typename CharT, std::size_t N>
-inline constexpr bool std::ranges::enable_borrowed_range<NonConstConvertibleReadOnlySpan<CharT, N>> = true;
-
-static_assert(std::ranges::borrowed_range<NonConstConvertibleReadOnlySpan<char>>);
-
-static_assert(!std::constructible_from<std::span<char>, NonConstConvertibleReadOnlySpan<char>>);
-static_assert(!std::convertible_to<NonConstConvertibleReadOnlySpan<char>, std::span<char>>);
-
-static_assert(!std::constructible_from<std::span<char>, const NonConstConvertibleReadOnlySpan<char>>);
-static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<char>, std::span<char>>);
-
-static_assert(std::constructible_from<std::span<const char>, NonConstConvertibleReadOnlySpan<char>>);
-static_assert(std::convertible_to<NonConstConvertibleReadOnlySpan<char>, std::span<const char>>);
-
-static_assert(!std::constructible_from<std::span<const char>, const NonConstConvertibleReadOnlySpan<char>>);
-static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<char>, std::span<const char>>);
-
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-static_assert(std::ranges::borrowed_range<NonConstConvertibleReadOnlySpan<wchar_t>>);
-
-static_assert(!std::constructible_from<std::span<wchar_t>, NonConstConvertibleReadOnlySpan<wchar_t>>);
-static_assert(!std::convertible_to<NonConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>);
-
-static_assert(!std::constructible_from<std::span<wchar_t>, const NonConstConvertibleReadOnlySpan<wchar_t>>);
-static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>);
-
-static_assert(std::constructible_from<std::span<const wchar_t>, NonConstConvertibleReadOnlySpan<wchar_t>>);
-static_assert(std::convertible_to<NonConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
-
-static_assert(!std::constructible_from<std::span<const wchar_t>, const NonConstConvertibleReadOnlySpan<wchar_t>>);
-static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
-#endif
-
 struct SomeObject {};
 
 struct NonMode {};
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
index 7a4f0f422404f4..6425b6ed94e493 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
@@ -29,28 +29,6 @@
 
 #include "../../helper_types.h"
 
-#ifndef TEST_HAS_NO_NASTY_STRING
-void test_sfinae_with_nasty_char() {
-  using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
-
-  // Non-const convertible
-  static_assert(std::constructible_from<SpStream, ReadOnlySpan<nasty_char>>);
-  static_assert(!test_convertible<SpStream, ReadOnlySpan<nasty_char>>());
-
-  // Const convertible
-  static_assert(!std::constructible_from<SpStream, const ReadOnlySpan<nasty_char>>);
-  static_assert(!test_convertible<SpStream, const ReadOnlySpan<nasty_char>>());
-
-  // Non-const non-convertible
-  static_assert(std::constructible_from<SpStream, ReadOnlySpan<nasty_char>>);
-  static_assert(!test_convertible<SpStream, ReadOnlySpan<nasty_char>>());
-
-  // Const non-convertible
-  static_assert(!std::constructible_from<SpStream, const ReadOnlySpan<nasty_char>>);
-  static_assert(!test_convertible<SpStream, const ReadOnlySpan<nasty_char>>());
-}
-#endif // TEST_HAS_NO_NASTY_STRING
-
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
   using SpStream =
@@ -95,7 +73,7 @@ void test() {
 
   {
     SpStream spSt(ros2);
-    assert(spSt.span().data() == arr);
+    assert(spSt.span().data() != arr);
     assert(spSt.span().data() == arr1);
     assert(spSt.span().empty());
     assert(spSt.span().size() == 0);
@@ -104,8 +82,7 @@ void test() {
 
 int main(int, char**) {
 #ifndef TEST_HAS_NO_NASTY_STRING
-  // test_sfinae<nasty_char, nasty_char_traits>();
-  test_sfinae_with_nasty_char();
+  test_sfinae<nasty_char, nasty_char_traits>();
 #endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();

>From f07ca85a7c5dd54cc3797aee56033ac6ee98f041 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 5 Mar 2024 09:50:42 +0200
Subject: [PATCH 20/29] Tests: Try to fix CI

---
 .../span.streams/ispanstream/ispanstream.cons/ros.pass.cpp    | 4 ++++
 libcxx/utils/generate_feature_test_macro_components.py        | 1 +
 2 files changed, 5 insertions(+)

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
index 6425b6ed94e493..b2cae9b9f54ced 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
@@ -32,9 +32,13 @@
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
   using SpStream =
+#ifndef TEST_HAS_NO_NASTY_STRING
       std::conditional_t<std::same_as<CharT, nasty_char>,
                          std::basic_ispanstream<nasty_char, nasty_char_traits>,
                          std::basic_ispanstream<CharT, TraitsT>>;
+#else
+      std::basic_ispanstream<CharT, TraitsT>;
+#endif
 
   // Non-const convertible
   static_assert(std::constructible_from<SpStream, ReadOnlySpan<CharT>>);
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 69bca109fca195..2837b9a92a7d82 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -1338,6 +1338,7 @@ def add_version_header(tc):
     "regex": ["UNSUPPORTED: no-localization"],
     "semaphore": ["UNSUPPORTED: no-threads"],
     "shared_mutex": ["UNSUPPORTED: no-threads"],
+    "spanstream": ["UNSUPPORTED: no-localization"],
     "sstream": ["UNSUPPORTED: no-localization"],
     "syncstream": ["UNSUPPORTED: no-localization"],
     "stdatomic.h": ["UNSUPPORTED: no-threads"],

>From d67cde74d15cf97f16736e562b0aac32bdc04517 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 5 Mar 2024 10:29:11 +0200
Subject: [PATCH 21/29] Tests: updated generated tests

---
 .../support.limits.general/spanstream.version.compile.pass.cpp  | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/spanstream.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/spanstream.version.compile.pass.cpp
index 8719352d4367e3..53c528e320a874 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/spanstream.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/spanstream.version.compile.pass.cpp
@@ -11,6 +11,8 @@
 //
 // clang-format off
 
+// UNSUPPORTED: no-localization
+
 // <spanstream>
 
 // Test the feature test macros defined by <spanstream>

>From 4ac0e41018f9092a95ecef9542f4a3ee47a3de20 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 5 Mar 2024 17:13:47 +0200
Subject: [PATCH 22/29] Tests: WIP

---
 .../ispanstream.cons/span.mode.pass.cpp       |  2 +-
 .../ospanstream.cons/span.mode.pass.cpp       | 27 +++++++------------
 .../spanbuf/spanbuf.cons/mode.pass.cpp        | 25 +++++++----------
 .../spanbuf/spanbuf.cons/span.mode.pass.cpp   |  2 +-
 .../spanstream.cons/span.mode.pass.cpp        | 13 ++++++---
 5 files changed, 31 insertions(+), 38 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
index 3527d197e7cdf9..a04cc578153b22 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
@@ -137,4 +137,4 @@ int main(int, char**) {
 #endif
 
   return 0;
-}
\ No newline at end of file
+}
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
index e036a0be4a48ba..bf619e8f18f7e7 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
@@ -33,23 +33,16 @@
 #include "../../helper_macros.h"
 #include "../../helper_types.h"
 
-#ifndef TEST_HAS_NO_NASTY_STRING
-void test_sfinae_with_nasty_char() {
-  using SpStream = std::basic_ospanstream<nasty_char, nasty_char_traits>;
-
-  // Mode
-  static_assert(std::constructible_from<SpStream, const std::span<nasty_char>, std::ios_base::openmode>);
-  static_assert(!test_convertible<SpStream, std::ios_base::openmode>());
-
-  // Non-mode
-  static_assert(!std::constructible_from<SpStream, const std::span<nasty_char>, const NonMode>);
-  static_assert(!test_convertible<SpStream, const std::span<nasty_char>, const NonMode>());
-}
-#endif // TEST_HAS_NO_NASTY_STRING
-
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
-  using SpStream = std::basic_ospanstream<CharT, TraitsT>;
+  using SpStream =
+#ifndef TEST_HAS_NO_NASTY_STRING
+      std::conditional_t<std::same_as<CharT, nasty_char>,
+                         std::basic_ispanstream<nasty_char, nasty_char_traits>,
+                         std::basic_ispanstream<CharT, TraitsT>>;
+#else
+      std::basic_ispanstream<CharT, TraitsT>;
+#endif
 
   // Mode
   static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
@@ -123,7 +116,7 @@ void test() {
 
 int main(int, char**) {
 #ifndef TEST_HAS_NO_NASTY_STRING
-  test_sfinae_with_nasty_char();
+  test_sfinae<nasty_char, nasty_char_traits>();
 #endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
@@ -137,4 +130,4 @@ int main(int, char**) {
 #endif
 
   return 0;
-}
\ No newline at end of file
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
index d040f0beb92a55..f4d7667ca8327f 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
@@ -30,23 +30,16 @@
 
 #include "../../helper_types.h"
 
-#ifndef TEST_HAS_NO_NASTY_STRING
-void test_sfinae_with_nasty_char() {
-  using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
-
-  // Mode
-  static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
-  static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
-
-  // Non-mode
-  static_assert(!std::constructible_from<SpBuf, const NonMode>);
-  static_assert(!test_convertible<SpBuf, const NonMode>());
-}
-#endif // TEST_HAS_NO_NASTY_STRING
-
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
-  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+  using SpStream =
+#ifndef TEST_HAS_NO_NASTY_STRING
+      std::conditional_t<std::same_as<CharT, nasty_char>,
+                         std::basic_ispanstream<nasty_char, nasty_char_traits>,
+                         std::basic_ispanstream<CharT, TraitsT>>;
+#else
+      std::basic_ispanstream<CharT, TraitsT>;
+#endif
 
   // Mode
   static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
@@ -88,7 +81,7 @@ void test() {
 
 int main(int, char**) {
 #ifndef TEST_HAS_NO_NASTY_STRING
-  test_sfinae_with_nasty_char();
+  test_sfinae<nasty_char, nasty_char_traits>();
 #endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
index 45985aed49c618..b0326f82451edd 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
@@ -188,4 +188,4 @@ int main(int, char**) {
 #endif
 
   return 0;
-}
\ No newline at end of file
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
index 2423c92fda9f8b..322ac32e1126cf 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
@@ -49,7 +49,14 @@ void test_sfinae_with_nasty_char() {
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
-  using SpStream = std::basic_spanstream<CharT, TraitsT>;
+  using SpStream =
+#ifndef TEST_HAS_NO_NASTY_STRING
+      std::conditional_t<std::same_as<CharT, nasty_char>,
+                         std::basic_ispanstream<nasty_char, nasty_char_traits>,
+                         std::basic_ispanstream<CharT, TraitsT>>;
+#else
+      std::basic_ispanstream<CharT, TraitsT>;
+#endif
 
   // Mode
   static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
@@ -123,7 +130,7 @@ void test() {
 
 int main(int, char**) {
 #ifndef TEST_HAS_NO_NASTY_STRING
-  test_sfinae_with_nasty_char();
+  test_sfinae<nasty_char>();
 #endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
@@ -137,4 +144,4 @@ int main(int, char**) {
 #endif
 
   return 0;
-}
\ No newline at end of file
+}

>From 7a1f00b31ca5807aed01e61018dc7ffdbe0f322a Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 5 Mar 2024 17:24:55 +0200
Subject: [PATCH 23/29] Tests: WIP cleanup

---
 .../ispanstream/ispanstream.cons/ros.pass.cpp |  9 +------
 .../ispanstream.cons/span.mode.pass.cpp       | 16 +-----------
 .../ospanstream.cons/span.mode.pass.cpp       |  9 +------
 .../spanbuf/spanbuf.cons/mode.pass.cpp        |  9 +------
 .../spanbuf/spanbuf.cons/span.mode.pass.cpp   | 16 +-----------
 .../spanstream.cons/span.mode.pass.cpp        | 25 ++-----------------
 6 files changed, 7 insertions(+), 77 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
index b2cae9b9f54ced..ac64e66725f154 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp
@@ -31,14 +31,7 @@
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
-  using SpStream =
-#ifndef TEST_HAS_NO_NASTY_STRING
-      std::conditional_t<std::same_as<CharT, nasty_char>,
-                         std::basic_ispanstream<nasty_char, nasty_char_traits>,
-                         std::basic_ispanstream<CharT, TraitsT>>;
-#else
-      std::basic_ispanstream<CharT, TraitsT>;
-#endif
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
 
   // Non-const convertible
   static_assert(std::constructible_from<SpStream, ReadOnlySpan<CharT>>);
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
index a04cc578153b22..55b2aaf5c3b2be 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp
@@ -33,20 +33,6 @@
 #include "../../helper_macros.h"
 #include "../../helper_types.h"
 
-#ifndef TEST_HAS_NO_NASTY_STRING
-void test_sfinae_with_nasty_char() {
-  using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
-
-  // Mode
-  static_assert(std::constructible_from<SpStream, const std::span<nasty_char>, std::ios_base::openmode>);
-  static_assert(!test_convertible<SpStream, std::ios_base::openmode>());
-
-  // Non-mode
-  static_assert(!std::constructible_from<SpStream, const std::span<nasty_char>, const NonMode>);
-  static_assert(!test_convertible<SpStream, const std::span<nasty_char>, const NonMode>());
-}
-#endif // TEST_HAS_NO_NASTY_STRING
-
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
   using SpStream = std::basic_ispanstream<CharT, TraitsT>;
@@ -123,7 +109,7 @@ void test() {
 
 int main(int, char**) {
 #ifndef TEST_HAS_NO_NASTY_STRING
-  test_sfinae_with_nasty_char();
+  test_sfinae<nasty_char, nasty_char_traits>();
 #endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
diff --git a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
index bf619e8f18f7e7..fe274e9208c622 100644
--- a/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp
@@ -35,14 +35,7 @@
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
-  using SpStream =
-#ifndef TEST_HAS_NO_NASTY_STRING
-      std::conditional_t<std::same_as<CharT, nasty_char>,
-                         std::basic_ispanstream<nasty_char, nasty_char_traits>,
-                         std::basic_ispanstream<CharT, TraitsT>>;
-#else
-      std::basic_ispanstream<CharT, TraitsT>;
-#endif
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
 
   // Mode
   static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
index f4d7667ca8327f..d2bd64f35cb59a 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp
@@ -32,14 +32,7 @@
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
-  using SpStream =
-#ifndef TEST_HAS_NO_NASTY_STRING
-      std::conditional_t<std::same_as<CharT, nasty_char>,
-                         std::basic_ispanstream<nasty_char, nasty_char_traits>,
-                         std::basic_ispanstream<CharT, TraitsT>>;
-#else
-      std::basic_ispanstream<CharT, TraitsT>;
-#endif
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
   // Mode
   static_assert(std::constructible_from<SpBuf, std::ios_base::openmode>);
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
index b0326f82451edd..fbfc2f144ab6d3 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp
@@ -33,20 +33,6 @@
 #include "../../helper_macros.h"
 #include "../../helper_types.h"
 
-#ifndef TEST_HAS_NO_NASTY_STRING
-void test_sfinae_with_nasty_char() {
-  using SpBuf = std::basic_spanbuf<nasty_char, nasty_char_traits>;
-
-  // Mode
-  static_assert(std::constructible_from<SpBuf, const std::span<nasty_char>, std::ios_base::openmode>);
-  static_assert(!test_convertible<SpBuf, std::ios_base::openmode>());
-
-  // Non-mode
-  static_assert(!std::constructible_from<SpBuf, const std::span<nasty_char>, const NonMode>);
-  static_assert(!test_convertible<SpBuf, const NonMode>());
-}
-#endif // TEST_HAS_NO_NASTY_STRING
-
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
   using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
@@ -174,7 +160,7 @@ void test() {
 
 int main(int, char**) {
 #ifndef TEST_HAS_NO_NASTY_STRING
-  test_sfinae_with_nasty_char();
+  test_sfinae<nasty_char, nasty_char_traits>();
 #endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();
diff --git a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
index 322ac32e1126cf..122d210430d9f1 100644
--- a/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp
@@ -33,30 +33,9 @@
 #include "../../helper_macros.h"
 #include "../../helper_types.h"
 
-#ifndef TEST_HAS_NO_NASTY_STRING
-void test_sfinae_with_nasty_char() {
-  using SpStream = std::basic_spanstream<nasty_char, nasty_char_traits>;
-
-  // Mode
-  static_assert(std::constructible_from<SpStream, const std::span<nasty_char>, std::ios_base::openmode>);
-  static_assert(!test_convertible<SpStream, std::ios_base::openmode>());
-
-  // Non-mode
-  static_assert(!std::constructible_from<SpStream, const std::span<nasty_char>, const NonMode>);
-  static_assert(!test_convertible<SpStream, const std::span<nasty_char>, const NonMode>());
-}
-#endif // TEST_HAS_NO_NASTY_STRING
-
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test_sfinae() {
-  using SpStream =
-#ifndef TEST_HAS_NO_NASTY_STRING
-      std::conditional_t<std::same_as<CharT, nasty_char>,
-                         std::basic_ispanstream<nasty_char, nasty_char_traits>,
-                         std::basic_ispanstream<CharT, TraitsT>>;
-#else
-      std::basic_ispanstream<CharT, TraitsT>;
-#endif
+  using SpStream = std::basic_ispanstream<CharT, TraitsT>;
 
   // Mode
   static_assert(std::constructible_from<SpStream, const std::span<CharT>, std::ios_base::openmode>);
@@ -130,7 +109,7 @@ void test() {
 
 int main(int, char**) {
 #ifndef TEST_HAS_NO_NASTY_STRING
-  test_sfinae<nasty_char>();
+  test_sfinae<nasty_char, nasty_char_traits>();
 #endif
   test_sfinae<char>();
   test_sfinae<char, constexpr_char_traits<char>>();

>From 56324ea1016ca46af6ca225af6565a7b433ece15 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 5 Mar 2024 17:55:59 +0200
Subject: [PATCH 24/29] Tests: added test skelettons

---
 .../ispanstream.assign/move.pass.cpp          |  2 +
 .../ispanstream.assign/swap.pass.cpp          |  2 +
 .../swap_nonmember.pass.cpp                   |  2 +
 .../spanbuf/spanbuf.assign/move.pass.cpp      | 82 ++++++++++++++++++
 .../spanbuf/spanbuf.assign/swap.pass.cpp      | 85 +++++++++++++++++++
 .../spanbuf.assign/swap_nonmember.pass.cpp    | 81 ++++++++++++++++++
 .../spanbuf/spanbuf.members/span.pass.cpp     | 58 +++++++++++++
 .../spanbuf.members/span.span.pass.cpp        | 59 +++++++++++++
 ...ekoff.off_type.seek_dir.open_mode.pass.cpp | 62 ++++++++++++++
 .../seekoff.pos_type.open_mode.pass.cpp       | 58 +++++++++++++
 .../spanbuf/spanbuf.virtuals/setbuf.pass.cpp  | 58 +++++++++++++
 11 files changed, 549 insertions(+)
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
 create mode 100644 libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp

diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/move.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/move.pass.cpp
index 117e2a6828e9da..75ae944d01c820 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/move.pass.cpp
@@ -34,6 +34,8 @@ void test() {
   CharT arr[4];
   std::span<CharT> sp{arr};
 
+  // TODO:
+
   // Mode: default
   {
     SpStream rhsSpSt{sp};
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap.pass.cpp
index 45fc6370a06d40..1aef6a3f476295 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap.pass.cpp
@@ -33,6 +33,8 @@ void test() {
   CharT arr[4];
   std::span<CharT> sp{arr};
 
+  // TODO:
+
   // Mode: default
   {
     SpStream rhsSpSt{sp};
diff --git a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap_nonmember.pass.cpp b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap_nonmember.pass.cpp
index ae54e409297454..165dc72673e9ff 100644
--- a/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap_nonmember.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.assign/swap_nonmember.pass.cpp
@@ -29,6 +29,8 @@ void test() {
   CharT arr[4];
   std::span<CharT> sp{arr};
 
+  // TODO:
+
   // Mode: default
   {
     SpStream rhsSpSt{sp};
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
new file mode 100644
index 00000000000000..798a4de1ae4d4a
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_streambuf<charT, traits> {
+
+//     // [spanbuf.cons], constructors
+//
+//     basic_spanbuf& operator=(basic_spanbuf&& rhs);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // TODO:
+  
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf = std::move(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::in};
+    SpBuf spBuf = std::move(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::out};
+    SpBuf spBuf = std::move(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpBuf spBuf = std::move(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
new file mode 100644
index 00000000000000..26aed41479890b
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_spanbuf<charT, traits> {
+
+//     // [ispanstream.swap], swap
+//     void swap(basic_spanbuf& rhs);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // TODO:
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::in};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::out};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
new file mode 100644
index 00000000000000..f92b77bfc1511a
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits>
+//     void swap(basic_spanbuf<charT, traits>& x, basic_spanbuf<charT, traits>& y);
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf= std::basic_spanbuf<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // TODO:
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    std::swap(spBuf, rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  // Mode: `ios_base::in`
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::in};
+    SpBuf spBuf(std::span<CharT>{});
+    std::swap(spBuf, rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  // Mode `ios_base::out`
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::out};
+    SpBuf spBuf(std::span<CharT>{});
+    std::swap(spBuf, rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+    SpBuf spBuf(std::span<CharT>{});
+    std::swap(spBuf, rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
new file mode 100644
index 00000000000000..25cee726941636
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_spanbuf<charT, traits> {
+
+//     // [spanbuf.members], member functions
+//     std::span<charT> span() const noexcept;
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // TODO:
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
new file mode 100644
index 00000000000000..9b696391b746f0
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
@@ -0,0 +1,59 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_spanbuf<charT, traits> {
+
+//     // [spanbuf.members], member functions
+//
+//     void span(std::span<charT> s) noexcept;
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // TODO:
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
new file mode 100644
index 00000000000000..039fa1f61c09a8
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_spanbuf<charT, traits> {
+
+//     // [spanbuf.virtuals], overridden virtual functions
+//
+//     pos_type seekoff(off_type off, ios_base::seekdir way,
+//                      ios_base::openmode which = ios_base::in | ios_base::out) override;
+//     pos_type seekpos(pos_type sp,
+//                      ios_base::openmode which = ios_base::in | ios_base::out) override;
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // TODO:
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
new file mode 100644
index 00000000000000..006d282cacc78b
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_spanbuf<charT, traits> {
+
+//     // [spanbuf.virtuals], overridden virtual functions
+//
+//     pos_type seekpos(pos_type sp,
+//                      ios_base::openmode which = ios_base::in | ios_base::out) override;
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp
new file mode 100644
index 00000000000000..fe9f5c3bf9cd89
--- /dev/null
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <spanstream>
+
+//   template<class charT, class traits = char_traits<charT>>
+//   class basic_spanbuf
+//     : public basic_spanbuf<charT, traits> {
+
+//     // [spanbuf.virtuals], overridden virtual functions
+//     basic_streambuf<charT, traits>* setbuf(charT*, streamsize) override;
+
+#include <cassert>
+#include <concepts>
+#include <span>
+#include <spanstream>
+
+#include "constexpr_char_traits.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+template <typename CharT, typename TraitsT = std::char_traits<CharT>>
+void test() {
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
+
+  CharT arr[4];
+  std::span<CharT> sp{arr};
+
+  // TODO:
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+}
+
+int main(int, char**) {
+  test<char>();
+  test<char, constexpr_char_traits<char>>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+  test<wchar_t, constexpr_char_traits<wchar_t>>();
+#endif
+
+  return 0;
+}

>From 7ff842c8c9ab619744c09273e74039fefda95833 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 5 Mar 2024 18:27:22 +0200
Subject: [PATCH 25/29] Tests: updated `iosfwd.pass.cpp`

---
 .../iostream.forward/iosfwd.pass.cpp          | 37 +++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/libcxx/test/std/input.output/iostream.forward/iosfwd.pass.cpp b/libcxx/test/std/input.output/iostream.forward/iosfwd.pass.cpp
index 1a28a5985a0112..bd9a6ae00de352 100644
--- a/libcxx/test/std/input.output/iostream.forward/iosfwd.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.forward/iosfwd.pass.cpp
@@ -83,6 +83,29 @@ int main(int, char**)
 #endif
     test<std::basic_stringstream<unsigned short>*>();
 
+#if TEST_STD_VER >= 23
+    test<std::basic_spanbuf<unsigned short>*>();
+    test<std::basic_spanbuf<char>*>();
+#  ifndef TEST_HAS_NO_WIDE_CHARACTERS
+    test<std::basic_spanbuf<wchar_t>*>();
+#  endif
+    test<std::basic_ispanstream<unsigned short>*>();
+    test<std::basic_ispanstream<char>*>();
+#  ifndef TEST_HAS_NO_WIDE_CHARACTERS
+    test<std::basic_ispanstream<wchar_t>*>();
+#  endif
+    test<std::basic_ospanstream<unsigned short>*>();
+    test<std::basic_ospanstream<char>*>();
+#  ifndef TEST_HAS_NO_WIDE_CHARACTERS
+    test<std::basic_ospanstream<wchar_t>*>();
+#  endif
+    test<std::basic_spanstream<char>*>();
+    test<std::basic_spanstream<unsigned short>*>();
+#  ifndef TEST_HAS_NO_WIDE_CHARACTERS
+    test<std::basic_spanstream<wchar_t>*>();
+#  endif
+#endif // TEST_STD_VER >= 23
+
     test<std::basic_filebuf<char>*          >();
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
     test<std::basic_filebuf<wchar_t>*       >();
@@ -134,6 +157,13 @@ int main(int, char**)
     test<std::ostringstream*>();
     test<std::stringstream* >();
 
+#if TEST_STD_VER >= 23
+    test<std::spanbuf*>();
+    test<std::ispanstream*>();
+    test<std::ospanstream*>();
+    test<std::spanstream*>();
+#endif // TEST_STD_VER >= 23
+
     test<std::filebuf* >();
     test<std::ifstream*>();
     test<std::ofstream*>();
@@ -150,6 +180,13 @@ int main(int, char**)
     test<std::wostringstream*>();
     test<std::wstringstream* >();
 
+#  if TEST_STD_VER >= 23
+    test<std::wspanbuf*>();
+    test<std::wispanstream*>();
+    test<std::wospanstream*>();
+    test<std::wspanstream*>();
+#  endif // TEST_STD_VER >= 23
+
     test<std::wfilebuf* >();
     test<std::wifstream*>();
     test<std::wofstream*>();

>From ebb2c0c596ba4218372fa483c48e4f270d689be2 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 5 Mar 2024 18:33:06 +0200
Subject: [PATCH 26/29] Tests: WIP fix test skelettons

---
 .../spanbuf/spanbuf.assign/move.pass.cpp      | 66 ++++++++--------
 .../spanbuf/spanbuf.assign/swap.pass.cpp      | 74 +++++++++---------
 .../spanbuf.assign/swap_nonmember.pass.cpp    | 76 +++++++++----------
 .../spanbuf/spanbuf.members/span.pass.cpp     | 20 ++---
 .../spanbuf.members/span.span.pass.cpp        | 18 ++---
 ...ekoff.off_type.seek_dir.open_mode.pass.cpp | 20 ++---
 .../seekoff.pos_type.open_mode.pass.cpp       | 20 ++---
 .../spanbuf/spanbuf.virtuals/setbuf.pass.cpp  | 18 ++---
 8 files changed, 156 insertions(+), 156 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
index 798a4de1ae4d4a..7702c2c51dbc82 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
@@ -35,39 +35,39 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-  
-  // Mode: default
-  {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf = std::move(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
-  // Mode: `ios_base::in`
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::in};
-    SpBuf spBuf = std::move(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
-  // Mode `ios_base::out`
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::out};
-    SpBuf spBuf = std::move(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(spBuf.span().empty());
-    assert(spBuf.span().size() == 0);
-  }
-  // Mode: multiple
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
-    SpBuf spBuf = std::move(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(spBuf.span().empty());
-    assert(spBuf.span().size() == 0);
-  }
+  (void)sp;
+  // // Mode: default
+  // {
+  //   SpBuf rhsSpBuf{sp};
+  //   SpBuf spBuf = std::move(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
+  // // Mode: `ios_base::in`
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::in};
+  //   SpBuf spBuf = std::move(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
+  // // Mode `ios_base::out`
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::out};
+  //   SpBuf spBuf = std::move(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(spBuf.span().empty());
+  //   assert(spBuf.span().size() == 0);
+  // }
+  // // Mode: multiple
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+  //   SpBuf spBuf = std::move(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(spBuf.span().empty());
+  //   assert(spBuf.span().size() == 0);
+  // }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
index 26aed41479890b..e5a2fff2ba8ba7 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
@@ -34,43 +34,43 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-
-  // Mode: default
-  {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
-  // Mode: `ios_base::in`
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::in};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
-  // Mode `ios_base::out`
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::out};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(spBuf.span().empty());
-    assert(spBuf.span().size() == 0);
-  }
-  // Mode: multiple
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(spBuf.span().empty());
-    assert(spBuf.span().size() == 0);
-  }
+  (void)sp;
+  // // Mode: default
+  // {
+  //   SpBuf rhsSpBuf{sp};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
+  // // Mode: `ios_base::in`
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::in};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
+  // // Mode `ios_base::out`
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::out};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(spBuf.span().empty());
+  //   assert(spBuf.span().size() == 0);
+  // }
+  // // Mode: multiple
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(spBuf.span().empty());
+  //   assert(spBuf.span().size() == 0);
+  // }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
index f92b77bfc1511a..e3342253bc741e 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
@@ -24,49 +24,49 @@
 
 template <typename CharT, typename TraitsT = std::char_traits<CharT>>
 void test() {
-  using SpBuf= std::basic_spanbuf<CharT, TraitsT>;
+  using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
   CharT arr[4];
   std::span<CharT> sp{arr};
 
   // TODO:
-
-  // Mode: default
-  {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    std::swap(spBuf, rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
-  // Mode: `ios_base::in`
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::in};
-    SpBuf spBuf(std::span<CharT>{});
-    std::swap(spBuf, rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
-  // Mode `ios_base::out`
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::out};
-    SpBuf spBuf(std::span<CharT>{});
-    std::swap(spBuf, rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(spBuf.span().empty());
-    assert(spBuf.span().size() == 0);
-  }
-  // Mode: multiple
-  {
-    SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
-    SpBuf spBuf(std::span<CharT>{});
-    std::swap(spBuf, rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(spBuf.span().empty());
-    assert(spBuf.span().size() == 0);
-  }
+  (void)sp;
+  // // Mode: default
+  // {
+  //   SpBuf rhsSpBuf{sp};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   std::swap(spBuf, rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
+  // // Mode: `ios_base::in`
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::in};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   std::swap(spBuf, rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
+  // // Mode `ios_base::out`
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::out};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   std::swap(spBuf, rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(spBuf.span().empty());
+  //   assert(spBuf.span().size() == 0);
+  // }
+  // // Mode: multiple
+  // {
+  //   SpBuf rhsSpBuf{sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   std::swap(spBuf, rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(spBuf.span().empty());
+  //   assert(spBuf.span().size() == 0);
+  // }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
index 25cee726941636..10316fe19f9ff7 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
@@ -34,16 +34,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-
-  // Mode: default
-  {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
+  (void)sp;
+  // // Mode: default
+  // {
+  //   SpBuf rhsSpBuf{sp};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
index 9b696391b746f0..8a0e3adc9df0e6 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
@@ -35,16 +35,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-
+  (void)sp;
   // Mode: default
-  {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
+  // {
+  //   SpBuf rhsSpBuf{sp};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
index 039fa1f61c09a8..341e9f3f61d242 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
@@ -38,16 +38,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-
-  // Mode: default
-  {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
+  (void)sp;
+  // // Mode: default
+  // {
+  //   SpBuf rhsSpBuf{sp};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
index 006d282cacc78b..08b6cade94fb3d 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
@@ -34,16 +34,16 @@ void test() {
 
   CharT arr[4];
   std::span<CharT> sp{arr};
-
-  // Mode: default
-  {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
+  (void)sp;
+  // // Mode: default
+  // {
+  //   SpBuf rhsSpBuf{sp};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp
index fe9f5c3bf9cd89..50e5b02a01c25b 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp
@@ -34,16 +34,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-
+  (void)sp;
   // Mode: default
-  {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    assert(spBuf.span().data() == arr);
-    assert(!spBuf.span().empty());
-    assert(spBuf.span().size() == 4);
-  }
+  // {
+  //   SpBuf rhsSpBuf{sp};
+  //   SpBuf spBuf(std::span<CharT>{});
+  //   spBuf.swap(rhsSpBuf);
+  //   assert(spBuf.span().data() == arr);
+  //   assert(!spBuf.span().empty());
+  //   assert(spBuf.span().size() == 4);
+  // }
 }
 
 int main(int, char**) {

>From 033f91530d8ce3ca2c9138578aba855565a89c42 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 5 Mar 2024 19:26:52 +0200
Subject: [PATCH 27/29] Tests: try to fix CI

---
 .../spanbuf/spanbuf.assign/move.pass.cpp      | 19 +++++++++---------
 .../spanbuf/spanbuf.assign/swap.pass.cpp      | 20 +++++++++----------
 .../spanbuf.assign/swap_nonmember.pass.cpp    | 20 +++++++++----------
 .../spanbuf/spanbuf.members/span.pass.cpp     | 20 +++++++++----------
 .../spanbuf.members/span.span.pass.cpp        | 18 ++++++++---------
 ...ekoff.off_type.seek_dir.open_mode.pass.cpp | 20 +++++++++----------
 .../seekoff.pos_type.open_mode.pass.cpp       | 20 +++++++++----------
 .../spanbuf/spanbuf.virtuals/setbuf.pass.cpp  | 18 ++++++++---------
 8 files changed, 78 insertions(+), 77 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
index 7702c2c51dbc82..c2cc8104707be4 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/move.pass.cpp
@@ -35,15 +35,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-  (void)sp;
-  // // Mode: default
-  // {
-  //   SpBuf rhsSpBuf{sp};
-  //   SpBuf spBuf = std::move(rhsSpBuf);
-  //   assert(spBuf.span().data() == arr);
-  //   assert(!spBuf.span().empty());
-  //   assert(spBuf.span().size() == 4);
-  // }
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf = std::move(rhsSpBuf);
+    (void)spBuf;
+    // assert(spBuf.span().data() == arr);
+    // assert(!spBuf.span().empty());
+    // assert(spBuf.span().size() == 4);
+  }
   // // Mode: `ios_base::in`
   // {
   //   SpBuf rhsSpBuf{sp, std::ios_base::in};
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
index e5a2fff2ba8ba7..cf036856f0b000 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap.pass.cpp
@@ -34,16 +34,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-  (void)sp;
-  // // Mode: default
-  // {
-  //   SpBuf rhsSpBuf{sp};
-  //   SpBuf spBuf(std::span<CharT>{});
-  //   spBuf.swap(rhsSpBuf);
-  //   assert(spBuf.span().data() == arr);
-  //   assert(!spBuf.span().empty());
-  //   assert(spBuf.span().size() == 4);
-  // }
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    // assert(spBuf.span().data() == arr);
+    // assert(!spBuf.span().empty());
+    // assert(spBuf.span().size() == 4);
+  }
   // // Mode: `ios_base::in`
   // {
   //   SpBuf rhsSpBuf{sp, std::ios_base::in};
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
index e3342253bc741e..d834332bdca156 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.assign/swap_nonmember.pass.cpp
@@ -30,16 +30,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-  (void)sp;
-  // // Mode: default
-  // {
-  //   SpBuf rhsSpBuf{sp};
-  //   SpBuf spBuf(std::span<CharT>{});
-  //   std::swap(spBuf, rhsSpBuf);
-  //   assert(spBuf.span().data() == arr);
-  //   assert(!spBuf.span().empty());
-  //   assert(spBuf.span().size() == 4);
-  // }
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    std::swap(spBuf, rhsSpBuf);
+    // assert(spBuf.span().data() == arr);
+    // assert(!spBuf.span().empty());
+    // assert(spBuf.span().size() == 4);
+  }
   // // Mode: `ios_base::in`
   // {
   //   SpBuf rhsSpBuf{sp, std::ios_base::in};
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
index 10316fe19f9ff7..98e8aef0330e9d 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
@@ -34,16 +34,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-  (void)sp;
-  // // Mode: default
-  // {
-  //   SpBuf rhsSpBuf{sp};
-  //   SpBuf spBuf(std::span<CharT>{});
-  //   spBuf.swap(rhsSpBuf);
-  //   assert(spBuf.span().data() == arr);
-  //   assert(!spBuf.span().empty());
-  //   assert(spBuf.span().size() == 4);
-  // }
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    // assert(spBuf.span().data() == arr);
+    // assert(!spBuf.span().empty());
+    // assert(spBuf.span().size() == 4);
+  }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
index 8a0e3adc9df0e6..3b3ef6704bade4 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
@@ -35,16 +35,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-  (void)sp;
+
   // Mode: default
-  // {
-  //   SpBuf rhsSpBuf{sp};
-  //   SpBuf spBuf(std::span<CharT>{});
-  //   spBuf.swap(rhsSpBuf);
-  //   assert(spBuf.span().data() == arr);
-  //   assert(!spBuf.span().empty());
-  //   assert(spBuf.span().size() == 4);
-  // }
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    // assert(spBuf.span().data() == arr);
+    // assert(!spBuf.span().empty());
+    // assert(spBuf.span().size() == 4);
+  }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
index 341e9f3f61d242..6b4580bedb89c2 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.off_type.seek_dir.open_mode.pass.cpp
@@ -38,16 +38,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-  (void)sp;
-  // // Mode: default
-  // {
-  //   SpBuf rhsSpBuf{sp};
-  //   SpBuf spBuf(std::span<CharT>{});
-  //   spBuf.swap(rhsSpBuf);
-  //   assert(spBuf.span().data() == arr);
-  //   assert(!spBuf.span().empty());
-  //   assert(spBuf.span().size() == 4);
-  // }
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    // assert(spBuf.span().data() == arr);
+    // assert(!spBuf.span().empty());
+    // assert(spBuf.span().size() == 4);
+  }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
index 08b6cade94fb3d..0980143e674075 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/seekoff.pos_type.open_mode.pass.cpp
@@ -34,16 +34,16 @@ void test() {
 
   CharT arr[4];
   std::span<CharT> sp{arr};
-  (void)sp;
-  // // Mode: default
-  // {
-  //   SpBuf rhsSpBuf{sp};
-  //   SpBuf spBuf(std::span<CharT>{});
-  //   spBuf.swap(rhsSpBuf);
-  //   assert(spBuf.span().data() == arr);
-  //   assert(!spBuf.span().empty());
-  //   assert(spBuf.span().size() == 4);
-  // }
+
+  // Mode: default
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    // assert(spBuf.span().data() == arr);
+    // assert(!spBuf.span().empty());
+    // assert(spBuf.span().size() == 4);
+  }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp
index 50e5b02a01c25b..193185da8d9ca3 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.virtuals/setbuf.pass.cpp
@@ -34,16 +34,16 @@ void test() {
   std::span<CharT> sp{arr};
 
   // TODO:
-  (void)sp;
+
   // Mode: default
-  // {
-  //   SpBuf rhsSpBuf{sp};
-  //   SpBuf spBuf(std::span<CharT>{});
-  //   spBuf.swap(rhsSpBuf);
-  //   assert(spBuf.span().data() == arr);
-  //   assert(!spBuf.span().empty());
-  //   assert(spBuf.span().size() == 4);
-  // }
+  {
+    SpBuf rhsSpBuf{sp};
+    SpBuf spBuf(std::span<CharT>{});
+    spBuf.swap(rhsSpBuf);
+    // assert(spBuf.span().data() == arr);
+    // assert(!spBuf.span().empty());
+    // assert(spBuf.span().size() == 4);
+  }
 }
 
 int main(int, char**) {

>From e5a678919dc49f739fa8bd739647c5e0ecf8d2de Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 6 Mar 2024 14:53:21 +0200
Subject: [PATCH 28/29] Tests: WIP `span.pass` and `span.span.pass`

---
 libcxx/include/spanstream                     | 13 +--
 .../input.output/span.streams/helper_types.h  | 23 ++---
 .../spanbuf/spanbuf.members/span.pass.cpp     | 20 ++--
 .../spanbuf.members/span.span.pass.cpp        | 94 +++++++++++++++++--
 4 files changed, 107 insertions(+), 43 deletions(-)

diff --git a/libcxx/include/spanstream b/libcxx/include/spanstream
index c735baaae93d90..f1ffd4f201368b 100644
--- a/libcxx/include/spanstream
+++ b/libcxx/include/spanstream
@@ -66,11 +66,12 @@
 #include <__utility/move.h>
 #include <__utility/swap.h>
 #include <iostream>
-// #include <print>
 #include <span>
 #include <streambuf>
 #include <version>
 
+// #include <print>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
@@ -98,11 +99,11 @@ public:
   _LIBCPP_HIDE_FROM_ABI basic_spanbuf() : basic_spanbuf(ios_base::in | ios_base::out) {}
 
   _LIBCPP_HIDE_FROM_ABI explicit basic_spanbuf(ios_base::openmode __which)
-      : basic_spanbuf(std::span<_CharT>(), __which) {}
+      : basic_streambuf<_CharT, _Traits>{}, __mode_{__which} {}
 
   _LIBCPP_HIDE_FROM_ABI explicit basic_spanbuf(std::span<_CharT> __s,
                                                ios_base::openmode __which = ios_base::in | ios_base::out)
-      : basic_streambuf<_CharT, _Traits>{}, __mode_{__which}, __buf_{__s} {
+      : basic_streambuf<_CharT, _Traits>{}, __mode_{__which} {
     this->span(__s);
   }
 
@@ -267,14 +268,8 @@ public:
     requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
   _LIBCPP_HIDE_FROM_ABI explicit basic_ispanstream(_ROSeq&& __s)
       : basic_istream<_CharT, _Traits>(std::addressof(__sb_)) {
-    // std::println(stderr, "ispanstream");
     std::span<const _CharT> __sp(std::forward<_ROSeq>(__s));
-    // std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
-    // std::println(stderr, "span data {} {}", __sp.empty(), __sp.size());
-    // std::println(stderr, "ispanstream 2");
     this->span(std::span<_CharT>(std::span<_CharT>(const_cast<_CharT*>(__sp.data()), __sp.size())));
-    // std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
-    // std::println(stderr, "ispanstream 3");
   }
 
   basic_ispanstream& operator=(const basic_ispanstream&) = delete;
diff --git a/libcxx/test/std/input.output/span.streams/helper_types.h b/libcxx/test/std/input.output/span.streams/helper_types.h
index 7f67432f9f8806..79760f97e223b6 100644
--- a/libcxx/test/std/input.output/span.streams/helper_types.h
+++ b/libcxx/test/std/input.output/span.streams/helper_types.h
@@ -16,7 +16,7 @@
 
 #include "test_macros.h"
 
-// #include <print>
+// ROS types
 
 template <typename CharT, std::size_t N = 0>
 class ReadOnlySpan {
@@ -25,19 +25,10 @@ class ReadOnlySpan {
 
   operator std::span<CharT>() = delete;
 
-  operator std::span<const CharT>() {
-    // std::println(stderr, "----> ROspan");
-    return std::span<const CharT, N>{arr_};
-  }
+  operator std::span<const CharT>() { return std::span<const CharT, N>{arr_}; }
 
-  const CharT* begin() {
-    // std::println(stderr, "----> ROspan begin");
-    return arr_;
-  }
-  const CharT* end() {
-    // std::println(stderr, "----> ROspan end");
-    return arr_ + N;
-  }
+  const CharT* begin() { return arr_; }
+  const CharT* end() { return arr_ + N; }
 
 private:
   CharT* arr_;
@@ -46,6 +37,8 @@ class ReadOnlySpan {
 template <typename CharT, std::size_t N>
 inline constexpr bool std::ranges::enable_borrowed_range<ReadOnlySpan<CharT, N>> = true;
 
+// Constraints: Constructors [ispanstream.cons]
+
 static_assert(std::ranges::borrowed_range<ReadOnlySpan<char>>);
 
 static_assert(!std::constructible_from<std::span<char>, ReadOnlySpan<char>>);
@@ -96,6 +89,8 @@ class NonReadOnlySpan {
 template <typename CharT, std::size_t N>
 inline constexpr bool std::ranges::enable_borrowed_range<NonReadOnlySpan<CharT, N>> = true;
 
+// Constraints: Constructors [ispanstream.cons]
+
 static_assert(std::ranges::borrowed_range<NonReadOnlySpan<char>>);
 
 static_assert(std::constructible_from<std::span<char>, NonReadOnlySpan<char>>);
@@ -126,7 +121,7 @@ static_assert(!std::constructible_from<std::span<const wchar_t>, const NonReadOn
 static_assert(!std::convertible_to<const NonReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
 #endif
 
-struct SomeObject {};
+// Mode types
 
 struct NonMode {};
 
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
index 98e8aef0330e9d..7d5ebea2903ea6 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
@@ -31,19 +31,17 @@ void test() {
   using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
   CharT arr[4];
-  std::span<CharT> sp{arr};
-
-  // TODO:
 
-  // Mode: default
+  std::span<CharT> sp{arr};
+  assert(sp.data() == arr);
+  assert(!sp.empty());
+  assert(sp.size() == 4);
+  
   {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    // assert(spBuf.span().data() == arr);
-    // assert(!spBuf.span().empty());
-    // assert(spBuf.span().size() == 4);
-  }
+  SpBuf spBuf(sp);
+  assert(spBuf.span().data() == arr);
+  assert(!spBuf.span().empty());
+  assert(spBuf.span().size() == 4);
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
index 3b3ef6704bade4..e1dfe517fe0d62 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
@@ -32,18 +32,94 @@ void test() {
   using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
 
   CharT arr[4];
-  std::span<CharT> sp{arr};
 
-  // TODO:
+  // Mode: default (`in` | `out`)
+  {
+    SpBuf spBuf;
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    spBuf.span(arr);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  {
+    SpBuf spBuf;
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    std::span<CharT> sp{arr};
+    assert(sp.data() == arr);
+    assert(!sp.empty());
+    assert(sp.size() == 4);
+
+    spBuf.span(sp);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: `in`
+  {
+    SpBuf spBuf{std::ios_base::in};
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    spBuf.span(arr);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  {
+    SpBuf spBuf{std::ios_base::in};
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    std::span<CharT> sp{arr};
+    assert(sp.data() == arr);
+    assert(!sp.empty());
+    assert(sp.size() == 4);
 
-  // Mode: default
+    spBuf.span(sp);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  // Mode: `out`
   {
-    SpBuf rhsSpBuf{sp};
-    SpBuf spBuf(std::span<CharT>{});
-    spBuf.swap(rhsSpBuf);
-    // assert(spBuf.span().data() == arr);
-    // assert(!spBuf.span().empty());
-    // assert(spBuf.span().size() == 4);
+    SpBuf spBuf{std::ios_base::out};
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    spBuf.span(arr);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  {
+    SpBuf spBuf{std::ios_base::out};
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    std::span<CharT> sp{arr};
+    assert(sp.data() == arr);
+    assert(!sp.empty());
+    assert(sp.size() == 4);
+
+    spBuf.span(sp);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
   }
 }
 

>From 5f36cf4fa0378b2e5e1e246f7da7bf9aa0bccd49 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 6 Mar 2024 21:59:17 +0200
Subject: [PATCH 29/29] Tests: updated `span.pass` and `span.span.pass`

---
 .../spanbuf/spanbuf.members/span.pass.cpp     | 36 ++++++++--
 .../spanbuf.members/span.span.pass.cpp        | 66 +++++++++++++++----
 2 files changed, 83 insertions(+), 19 deletions(-)

diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
index 7d5ebea2903ea6..635b8d2a030733 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.pass.cpp
@@ -36,12 +36,38 @@ void test() {
   assert(sp.data() == arr);
   assert(!sp.empty());
   assert(sp.size() == 4);
-  
+
+  // Mode: default (`in` | `out`)
+  {
+    SpBuf spBuf(sp);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: `in`
+  {
+    SpBuf spBuf(sp, std::ios_base::in);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  // Mode: `out`
+  {
+    SpBuf spBuf(sp, std::ios_base::out);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: multiple
   {
-  SpBuf spBuf(sp);
-  assert(spBuf.span().data() == arr);
-  assert(!spBuf.span().empty());
-  assert(spBuf.span().size() == 4);
+    SpBuf spBuf(sp, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
 }
 
 int main(int, char**) {
diff --git a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
index e1dfe517fe0d62..5495cdefbe7c68 100644
--- a/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
+++ b/libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.members/span.span.pass.cpp
@@ -33,6 +33,11 @@ void test() {
 
   CharT arr[4];
 
+  std::span<CharT> sp{arr};
+  assert(sp.data() == arr);
+  assert(!sp.empty());
+  assert(sp.size() == 4);
+
   // Mode: default (`in` | `out`)
   {
     SpBuf spBuf;
@@ -52,11 +57,6 @@ void test() {
     assert(spBuf.span().empty());
     assert(spBuf.span().size() == 0);
 
-    std::span<CharT> sp{arr};
-    assert(sp.data() == arr);
-    assert(!sp.empty());
-    assert(sp.size() == 4);
-
     spBuf.span(sp);
     assert(spBuf.span().data() == arr);
     // Mode `out` counts read characters
@@ -81,11 +81,6 @@ void test() {
     assert(spBuf.span().empty());
     assert(spBuf.span().size() == 0);
 
-    std::span<CharT> sp{arr};
-    assert(sp.data() == arr);
-    assert(!sp.empty());
-    assert(sp.size() == 4);
-
     spBuf.span(sp);
     assert(spBuf.span().data() == arr);
     assert(!spBuf.span().empty());
@@ -110,10 +105,30 @@ void test() {
     assert(spBuf.span().empty());
     assert(spBuf.span().size() == 0);
 
-    std::span<CharT> sp{arr};
-    assert(sp.data() == arr);
-    assert(!sp.empty());
-    assert(sp.size() == 4);
+    spBuf.span(sp);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  // Mode: multiple
+  {
+    SpBuf spBuf(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    spBuf.span(arr);
+    assert(spBuf.span().data() == arr);
+    // Mode `out` counts read characters
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+  }
+  {
+    SpBuf spBuf(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
 
     spBuf.span(sp);
     assert(spBuf.span().data() == arr);
@@ -121,6 +136,29 @@ void test() {
     assert(spBuf.span().empty());
     assert(spBuf.span().size() == 0);
   }
+  // Mode: `ate`
+  {
+    SpBuf spBuf(std::ios_base::out | std::ios_base::ate);
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    spBuf.span(arr);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
+  {
+    SpBuf spBuf(std::ios_base::out | std::ios_base::ate);
+    assert(spBuf.span().data() == nullptr);
+    assert(spBuf.span().empty());
+    assert(spBuf.span().size() == 0);
+
+    spBuf.span(sp);
+    assert(spBuf.span().data() == arr);
+    assert(!spBuf.span().empty());
+    assert(spBuf.span().size() == 4);
+  }
 }
 
 int main(int, char**) {



More information about the libcxx-commits mailing list