libstdc++: Implement C++20 features for <sstream>

Message ID 20201007165526.2565948-1-rodgert@appliantology.com
State Superseded
Headers show
Series
  • libstdc++: Implement C++20 features for <sstream>
Related show

Commit Message

Thomas Rodgers Oct. 7, 2020, 4:55 p.m.
From: Thomas Rodgers <trodgers@redhat.com>


New ctors and ::view() accessor for -
  * basic_stingbuf
  * basic_istringstream
  * basic_ostringstream
  * basic_stringstreamm

New ::get_allocator() accessor for basic_stringbuf.

libstdc++-v3/ChangeLog:
	* acinclude.m4 (glibcxx_SUBDIRS): Add src/c++20.
        * config/abi/pre/gnu.ver: Update GLIBCXX_3.4.29 for the addition of -
	basic_stringbuf::basic_stringbuf(allocator const&),
	basic_stringbuf::basic_stringbuf(openmode, allocator const&),
	basic_stringbuf::basic_stringbuf(basic_string&&, openmode),
	basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&),
	basic_stringbuf::get_allocator(),
	basic_stringbuf::view(),
	basic_istringstream::basic_istringstream(basic_string&&, openmode),
	basic_istringstream::basic_istringstream(openmode, allocator const&),
	basic_istringstream::view(),
	basic_ostringstream::basic_ostringstream(basic_string&&, openmode),
	basic_ostringstream::basic_ostringstream(openmode, allocator const&),
	basic_ostringstream::view(),
	basic_stringstream::basic_stringstream(basic_string&&, openmode),
	basic_stringstream::basic_stringstream(openmode, allocator const&),
	basic_stringstream::view().
	* configure: Regenerate.
	* include/std/sstream:
	(basic_stringbuf::basic_stringbuf(allocator const&)): New constructor.
	(basic_stringbuf::basic_stringbuf(openmode, allocator const&)): Likewise.
	(basic_stringbuf::basic_stringbuf(basic_string&&, openmode)): Likewise.
	(basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&)): Likewise.
	(basic_stringbuf::get_allocator()): New method.
	(basic_stringbuf::view()): Likewise.
	(basic_istringstream::basic_istringstream(basic_string&&, openmode)):
	New constructor.
	(basic_istringstream::basic_istringstream(openmode, allocator const&)):
	Likewise
	(basic_istringstream::view()): New method.
	(basic_ostringstream::basic_ostringstream(basic_string&&, openmode)):
	New constructor.
	(basic_ostringstream::basic_ostringstream(openmode, allocator const&)):
	Likewise
	(basic_ostringstream::view()): New method.
	(basic_stringstream::basic_stringstream(basic_string&&, openmode)):
	New constructor.
	(basic_stringstream::basic_stringstream(openmode, allocator const&)):
	Likewise
	(basic_stringstream::view()): New method.
	* src/Makefile.in: Add c++20 directory.
	* src/Makefile.am: Regenerate.
	* src/c++20/Makefile.am: Add makefile for new sub-directory.
	* src/c++20/Makefile.in: Generate.
	* src/c++20/sstream-inst.cc: New file defining explicit
	instantiations for basic_stringbuf, basic_istringstream,
	basic_ostringstream, and basic_stringstream member functions
	added in C++20.
	* testsuite/27_io/basic_stringbuf/cons/char/2.cc: New test.
	* testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/view/char/2.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/view/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_istringstream/cons/char/2.cc: Likewise.
	* testsuite/27_io/basic_istringstream/cons/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_istringstream/view/char/2.cc: Likewise.
	* testsuite/27_io/basic_istringstream/view/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/cons/char/2.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/cons/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/view/char/2.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/view/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_stringstream/cons/char/2.cc: Likewise.
	* testsuite/27_io/basic_stringstream/cons/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_stringstream/view/char/2.cc: Likewise.
	* testsuite/27_io/basic_stringstream/view/wchar_t/2.cc: Likewise.
---
 .topdeps                                      |   1 +
 .topmsg                                       |   2 +
 libstdc++-v3/acinclude.m4                     |   2 +-
 libstdc++-v3/config/abi/pre/gnu.ver           |  60 ++
 libstdc++-v3/configure                        |  16 +-
 libstdc++-v3/include/std/sstream              | 198 +++++
 libstdc++-v3/src/Makefile.am                  |  12 +-
 libstdc++-v3/src/Makefile.in                  |  14 +-
 libstdc++-v3/src/c++20/Makefile.am            | 105 +++
 libstdc++-v3/src/c++20/Makefile.in            | 735 ++++++++++++++++++
 libstdc++-v3/src/c++20/sstream-inst.cc        | 110 +++
 .../27_io/basic_istringstream/cons/char/1.cc  |  84 ++
 .../basic_istringstream/cons/wchar_t/1.cc     |  84 ++
 .../27_io/basic_istringstream/view/char/1.cc  |  34 +
 .../basic_istringstream/view/wchar_t/1.cc     |  35 +
 .../27_io/basic_ostringstream/cons/char/1.cc  |  84 ++
 .../basic_ostringstream/cons/wchar_t/1.cc     |  84 ++
 .../27_io/basic_ostringstream/view/char/1.cc  |  34 +
 .../basic_ostringstream/view/wchar_t/1.cc     |  35 +
 .../27_io/basic_stringbuf/cons/char/2.cc      | 120 +++
 .../27_io/basic_stringbuf/cons/wchar_t/2.cc   | 105 +++
 .../27_io/basic_stringbuf/view/char/1.cc      |  34 +
 .../27_io/basic_stringbuf/view/wchar_t/1.cc   |  35 +
 .../27_io/basic_stringstream/cons/char/1.cc   |  84 ++
 .../basic_stringstream/cons/wchar_t/1.cc      |  84 ++
 .../27_io/basic_stringstream/view/char/1.cc   |  34 +
 .../basic_stringstream/view/wchar_t/1.cc      |  35 +
 27 files changed, 2248 insertions(+), 12 deletions(-)
 create mode 100644 .topdeps
 create mode 100644 .topmsg
 create mode 100644 libstdc++-v3/src/c++20/Makefile.am
 create mode 100644 libstdc++-v3/src/c++20/Makefile.in
 create mode 100644 libstdc++-v3/src/c++20/sstream-inst.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/view/char/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/view/wchar_t/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/view/char/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/view/char/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/view/char/1.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/view/wchar_t/1.cc

-- 
2.26.2

Comments

Richard Earnshaw via Gcc-patches Oct. 7, 2020, 7:44 p.m. | #1
On 07/10/20 09:55 -0700, Thomas Rodgers wrote:
>From: Thomas Rodgers <trodgers@redhat.com>

>

>New ctors and ::view() accessor for -

>  * basic_stingbuf

>  * basic_istringstream

>  * basic_ostringstream

>  * basic_stringstreamm

>

>New ::get_allocator() accessor for basic_stringbuf.

>

>libstdc++-v3/ChangeLog:

>	* acinclude.m4 (glibcxx_SUBDIRS): Add src/c++20.

>        * config/abi/pre/gnu.ver: Update GLIBCXX_3.4.29 for the addition of -

>	basic_stringbuf::basic_stringbuf(allocator const&),

>	basic_stringbuf::basic_stringbuf(openmode, allocator const&),

>	basic_stringbuf::basic_stringbuf(basic_string&&, openmode),

>	basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&),

>	basic_stringbuf::get_allocator(),

>	basic_stringbuf::view(),

>	basic_istringstream::basic_istringstream(basic_string&&, openmode),

>	basic_istringstream::basic_istringstream(openmode, allocator const&),

>	basic_istringstream::view(),

>	basic_ostringstream::basic_ostringstream(basic_string&&, openmode),

>	basic_ostringstream::basic_ostringstream(openmode, allocator const&),

>	basic_ostringstream::view(),

>	basic_stringstream::basic_stringstream(basic_string&&, openmode),

>	basic_stringstream::basic_stringstream(openmode, allocator const&),

>	basic_stringstream::view().

>	* configure: Regenerate.

>	* include/std/sstream:

>	(basic_stringbuf::basic_stringbuf(allocator const&)): New constructor.

>	(basic_stringbuf::basic_stringbuf(openmode, allocator const&)): Likewise.

>	(basic_stringbuf::basic_stringbuf(basic_string&&, openmode)): Likewise.

>	(basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&)): Likewise.

>	(basic_stringbuf::get_allocator()): New method.

>	(basic_stringbuf::view()): Likewise.

>	(basic_istringstream::basic_istringstream(basic_string&&, openmode)):

>	New constructor.

>	(basic_istringstream::basic_istringstream(openmode, allocator const&)):

>	Likewise

>	(basic_istringstream::view()): New method.

>	(basic_ostringstream::basic_ostringstream(basic_string&&, openmode)):

>	New constructor.

>	(basic_ostringstream::basic_ostringstream(openmode, allocator const&)):

>	Likewise

>	(basic_ostringstream::view()): New method.

>	(basic_stringstream::basic_stringstream(basic_string&&, openmode)):

>	New constructor.

>	(basic_stringstream::basic_stringstream(openmode, allocator const&)):

>	Likewise

>	(basic_stringstream::view()): New method.

>	* src/Makefile.in: Add c++20 directory.

>	* src/Makefile.am: Regenerate.

>	* src/c++20/Makefile.am: Add makefile for new sub-directory.

>	* src/c++20/Makefile.in: Generate.

>	* src/c++20/sstream-inst.cc: New file defining explicit

>	instantiations for basic_stringbuf, basic_istringstream,

>	basic_ostringstream, and basic_stringstream member functions

>	added in C++20.

>	* testsuite/27_io/basic_stringbuf/cons/char/2.cc: New test.

>	* testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.

>	* testsuite/27_io/basic_stringbuf/view/char/2.cc: Likewise.

>	* testsuite/27_io/basic_stringbuf/view/wchar_t/2.cc: Likewise.

>	* testsuite/27_io/basic_istringstream/cons/char/2.cc: Likewise.

>	* testsuite/27_io/basic_istringstream/cons/wchar_t/2.cc: Likewise.

>	* testsuite/27_io/basic_istringstream/view/char/2.cc: Likewise.

>	* testsuite/27_io/basic_istringstream/view/wchar_t/2.cc: Likewise.

>	* testsuite/27_io/basic_ostringstream/cons/char/2.cc: Likewise.

>	* testsuite/27_io/basic_ostringstream/cons/wchar_t/2.cc: Likewise.

>	* testsuite/27_io/basic_ostringstream/view/char/2.cc: Likewise.

>	* testsuite/27_io/basic_ostringstream/view/wchar_t/2.cc: Likewise.

>	* testsuite/27_io/basic_stringstream/cons/char/2.cc: Likewise.

>	* testsuite/27_io/basic_stringstream/cons/wchar_t/2.cc: Likewise.

>	* testsuite/27_io/basic_stringstream/view/char/2.cc: Likewise.

>	* testsuite/27_io/basic_stringstream/view/wchar_t/2.cc: Likewise.

>---

> .topdeps                                      |   1 +

> .topmsg                                       |   2 +

> libstdc++-v3/acinclude.m4                     |   2 +-

> libstdc++-v3/config/abi/pre/gnu.ver           |  60 ++

> libstdc++-v3/configure                        |  16 +-

> libstdc++-v3/include/std/sstream              | 198 +++++

> libstdc++-v3/src/Makefile.am                  |  12 +-

> libstdc++-v3/src/Makefile.in                  |  14 +-

> libstdc++-v3/src/c++20/Makefile.am            | 105 +++

> libstdc++-v3/src/c++20/Makefile.in            | 735 ++++++++++++++++++

> libstdc++-v3/src/c++20/sstream-inst.cc        | 110 +++

> .../27_io/basic_istringstream/cons/char/1.cc  |  84 ++

> .../basic_istringstream/cons/wchar_t/1.cc     |  84 ++

> .../27_io/basic_istringstream/view/char/1.cc  |  34 +

> .../basic_istringstream/view/wchar_t/1.cc     |  35 +

> .../27_io/basic_ostringstream/cons/char/1.cc  |  84 ++

> .../basic_ostringstream/cons/wchar_t/1.cc     |  84 ++

> .../27_io/basic_ostringstream/view/char/1.cc  |  34 +

> .../basic_ostringstream/view/wchar_t/1.cc     |  35 +

> .../27_io/basic_stringbuf/cons/char/2.cc      | 120 +++

> .../27_io/basic_stringbuf/cons/wchar_t/2.cc   | 105 +++

> .../27_io/basic_stringbuf/view/char/1.cc      |  34 +

> .../27_io/basic_stringbuf/view/wchar_t/1.cc   |  35 +

> .../27_io/basic_stringstream/cons/char/1.cc   |  84 ++

> .../basic_stringstream/cons/wchar_t/1.cc      |  84 ++

> .../27_io/basic_stringstream/view/char/1.cc   |  34 +

> .../basic_stringstream/view/wchar_t/1.cc      |  35 +

> 27 files changed, 2248 insertions(+), 12 deletions(-)

> create mode 100644 .topdeps

> create mode 100644 .topmsg

> create mode 100644 libstdc++-v3/src/c++20/Makefile.am

> create mode 100644 libstdc++-v3/src/c++20/Makefile.in

> create mode 100644 libstdc++-v3/src/c++20/sstream-inst.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/view/char/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_istringstream/view/wchar_t/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/view/char/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/view/char/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/view/char/1.cc

> create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringstream/view/wchar_t/1.cc

>

>diff --git a/.topdeps b/.topdeps

>new file mode 100644

>index 00000000000..1f7391f92b6

>--- /dev/null

>+++ b/.topdeps

>@@ -0,0 +1 @@

>+master

>diff --git a/.topmsg b/.topmsg

>new file mode 100644

>index 00000000000..0c035ed2f0c

>--- /dev/null

>+++ b/.topmsg

>@@ -0,0 +1,2 @@

>+From: Thomas Rodgers <trodgers@redhat.com>

>+Subject: [PATCH] t/trodgers/c2a_sstream

>diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4

>index 133125ec4fa..b9452dd74cd 100644

>--- a/libstdc++-v3/acinclude.m4

>+++ b/libstdc++-v3/acinclude.m4

>@@ -49,7 +49,7 @@ AC_DEFUN([GLIBCXX_CONFIGURE], [

>   # Keep these sync'd with the list in Makefile.am.  The first provides an

>   # expandable list at autoconf time; the second provides an expandable list

>   # (i.e., shell variable) at configure time.

>-  m4_define([glibcxx_SUBDIRS],[include libsupc++ src src/c++98 src/c++11 src/c++17 src/filesystem doc po testsuite python])

>+  m4_define([glibcxx_SUBDIRS],[include libsupc++ src src/c++98 src/c++11 src/c++17 src/c++20 src/filesystem doc po testsuite python])

>   SUBDIRS='glibcxx_SUBDIRS'

>

>   # These need to be absolute paths, yet at the same time need to

>diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver

>index 87a48a21f53..3239bb1a53d 100644

>--- a/libstdc++-v3/config/abi/pre/gnu.ver

>+++ b/libstdc++-v3/config/abi/pre/gnu.ver

>@@ -2322,6 +2322,66 @@ GLIBCXX_3.4.29 {

>     # std::__atomic_futex_unsigned_base::_M_futex_wait_until_steady

>     _ZNSt28__atomic_futex_unsigned_base26_M_futex_wait_until_steady*;

>

>+    # basic_stringbuf::basic_stringbuf(allocator const&)

>+    _ZNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEC1ERKS3_;

>+    _ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEEC1ERKS3_;


Please combine these symbols by using [cw] wherever the char_type
appears e.g.

     # basic_stringbuf::basic_stringbuf(allocator const&)
     _ZNSt7__cxx1115basic_stringbufI[cw]St11char_traitsI[cw]ESaI[cw]EEC1ERKS3_;

>diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure

>index 7abf1b1ccc1..eecf63f4a59 100755

>--- a/libstdc++-v3/configure

>+++ b/libstdc++-v3/configure


This is a generated file so can be filtered out of the patch.


>diff --git a/libstdc++-v3/src/c++20/sstream-inst.cc b/libstdc++-v3/src/c++20/sstream-inst.cc

>new file mode 100644

>index 00000000000..c7fa065bf18

>--- /dev/null

>+++ b/libstdc++-v3/src/c++20/sstream-inst.cc

>@@ -0,0 +1,110 @@

>+// Explicit instantiation file.

>+

>+// Copyright (C) 1997-2020 Free Software Foundation, Inc.

>+//

>+// This file is part of the GNU ISO C++ Library.  This library is free

>+// software; you can redistribute it and/or modify it under the

>+// terms of the GNU General Public License as published by the

>+// Free Software Foundation; either version 3, or (at your option)

>+// any later version.

>+

>+// This library is distributed in the hope that it will be useful,

>+// but WITHOUT ANY WARRANTY; without even the implied warranty of

>+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

>+// GNU General Public License for more details.

>+

>+// Under Section 7 of GPL version 3, you are granted additional

>+// permissions described in the GCC Runtime Library Exception, version

>+// 3.1, as published by the Free Software Foundation.

>+

>+// You should have received a copy of the GNU General Public License and

>+// a copy of the GCC Runtime Library Exception along with this program;

>+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see

>+// <http://www.gnu.org/licenses/>.

>+

>+//

>+// ISO C++ 14882:

>+//

>+

>+#ifndef _GLIBCXX_USE_CXX11_ABI

>+// Instantiations in this file use the new SSO std::string ABI unless included

>+// by another file which defines _GLIBCXX_USE_CXX11_ABI=0.

>+# define _GLIBCXX_USE_CXX11_ABI 1

>+#endif


Nothing includes this with _GLIBCXX_USE_CXX11_ABI=0 defined. That
means all the tests will fail if run with that defined, e.g.

make check RUNTESTFLAGS="conformance.exp=27_io/*string* --target_board=unix/-D_GLIBCXX_USE_CXX11_ABI=0"

Either you need to add a src/c++20/cow-sstream-inst.cc file that does:

#define _GLIBCXX_USE_CXX11_ABI 0
#include "sstream-inst.cc"

and then export all the resulting symbols, or the new features should
only be defined for the new ABI, i.e. instead of

#if __cplusplus > 201703L

they should be guarded by

#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI


I'm not sure how feasible it is to make the new features work with the
old ABI, as the old std::string doesn't propagate allocators properly.
It might just work with no extra effort needed though.

If it doesn't work, and the features are disabled for the old ABI,
then all the new tests need:

// { dg-require-effective-target cxx11-abi }

so that they are skipped as UNSUPPORTED when run with
_GLIBCXX_USE_CXX11_ABI=0 defined.
Richard Earnshaw via Gcc-patches Nov. 4, 2020, 7:54 p.m. | #2
On 07/10/2020 18:55, Thomas Rodgers wrote:
> From: Thomas Rodgers <trodgers@redhat.com>

> 

> New ctors and ::view() accessor for -

>    * basic_stingbuf

>    * basic_istringstream

>    * basic_ostringstream

>    * basic_stringstreamm

> 

> New ::get_allocator() accessor for basic_stringbuf.

I found that this 
<https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a0e4d7b44c544c84cffc7ff9c64b6f1af14fb08d> 
"libstdc++: Implement C++20 features for <sstream>" changed the behavior of

> $ cat test.cc

> #include <iostream>

> #include <iterator>

> #include <sstream>

> int main() {

>   std::stringstream s("a");

>   std::istreambuf_iterator<char> i(s);

>   if (i != std::istreambuf_iterator<char>()) std::cout << *i << '\n';

> }

> 

> $ g++ -std=c++20 test.cc

> $ ./a.out


from printing "a" to printing nothing.  (The `i != ...` comparison 
appears to change i from pointing at "a" to pointing to null, and 
returns false.)

I ran into this when building LibreOffice, and I hope test.cc is a 
faithfully minimized reproducer.  However, I know little about 
std::istreambuf_iterator, so it may well be that the code isn't even valid.
Thomas Rodgers Nov. 4, 2020, 8:43 p.m. | #3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97719

> On Nov 4, 2020, at 11:54 AM, Stephan Bergmann <sbergman@redhat.com> wrote:

> 

> On 07/10/2020 18:55, Thomas Rodgers wrote:

>> From: Thomas Rodgers <trodgers@redhat.com>

>> New ctors and ::view() accessor for -

>>   * basic_stingbuf

>>   * basic_istringstream

>>   * basic_ostringstream

>>   * basic_stringstreamm

>> New ::get_allocator() accessor for basic_stringbuf.

> I found that this <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a0e4d7b44c544c84cffc7ff9c64b6f1af14fb08d> "libstdc++: Implement C++20 features for <sstream>" changed the behavior of

> 

>> $ cat test.cc

>> #include <iostream>

>> #include <iterator>

>> #include <sstream>

>> int main() {

>>  std::stringstream s("a");

>>  std::istreambuf_iterator<char> i(s);

>>  if (i != std::istreambuf_iterator<char>()) std::cout << *i << '\n';

>> }

>> $ g++ -std=c++20 test.cc

>> $ ./a.out

> 

> from printing "a" to printing nothing.  (The `i != ...` comparison appears to change i from pointing at "a" to pointing to null, and returns false.)

> 

> I ran into this when building LibreOffice, and I hope test.cc is a faithfully minimized reproducer.  However, I know little about std::istreambuf_iterator, so it may well be that the code isn't even valid.

>
Richard Earnshaw via Gcc-patches Nov. 4, 2020, 9:45 p.m. | #4
On 04/11/20 12:43 -0800, Thomas Rodgers wrote:
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97719

>

>> On Nov 4, 2020, at 11:54 AM, Stephan Bergmann <sbergman@redhat.com> wrote:

>>

>> On 07/10/2020 18:55, Thomas Rodgers wrote:

>>> From: Thomas Rodgers <trodgers@redhat.com>

>>> New ctors and ::view() accessor for -

>>>   * basic_stingbuf

>>>   * basic_istringstream

>>>   * basic_ostringstream

>>>   * basic_stringstreamm

>>> New ::get_allocator() accessor for basic_stringbuf.

>> I found that this <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a0e4d7b44c544c84cffc7ff9c64b6f1af14fb08d> "libstdc++: Implement C++20 features for <sstream>" changed the behavior of

>>

>>> $ cat test.cc

>>> #include <iostream>

>>> #include <iterator>

>>> #include <sstream>

>>> int main() {

>>>  std::stringstream s("a");

>>>  std::istreambuf_iterator<char> i(s);

>>>  if (i != std::istreambuf_iterator<char>()) std::cout << *i << '\n';

>>> }

>>> $ g++ -std=c++20 test.cc

>>> $ ./a.out

>>

>> from printing "a" to printing nothing.  (The `i != ...` comparison appears to change i from pointing at "a" to pointing to null, and returns false.)

>>

>> I ran into this when building LibreOffice, and I hope test.cc is a faithfully minimized reproducer.  However, I know little about std::istreambuf_iterator, so it may well be that the code isn't even valid.

>>


I'm testing this patch.
commit 1ca2fe0fc85403c6ea4e0775b5da051ff0eebc96
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Nov 4 21:44:05 2020

    libstdc++: Fix default mode of new basic_stringstream constructor [PR 97719]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/97719
            * include/std/sstream (basic_stringstream(string_type&&, openmode)):
            Fix default argument.
            * testsuite/27_io/basic_stringstream/cons/char/97719.cc: New test.

diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index 33a00486606c..8acf1eb259ab 100644
--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -976,7 +976,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 
       explicit
       basic_stringstream(__string_type&& __str,
-	                 ios_base::openmode __mode = ios_base::out
+	                 ios_base::openmode __mode = ios_base::in
 						     | ios_base::out)
       : __iostream_type(), _M_stringbuf(std::move(__str), __mode)
       { this->init(std::__addressof(_M_stringbuf)); }
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc
new file mode 100644
index 000000000000..fa523a803b6d
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc
@@ -0,0 +1,40 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  // PR libstdc++/97719
+  std::string str = "a";
+  std::stringstream s(std::move(str));
+  std::istreambuf_iterator<char> i(s);
+  VERIFY( i != std::istreambuf_iterator<char>() );
+  VERIFY( *i == 'a' );
+}
+
+int
+main()
+{
+  test01();
+}
Richard Earnshaw via Gcc-patches Nov. 4, 2020, 11:41 p.m. | #5
On 04/11/20 21:45 +0000, Jonathan Wakely wrote:
>On 04/11/20 12:43 -0800, Thomas Rodgers wrote:

>>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97719

>>

>>>On Nov 4, 2020, at 11:54 AM, Stephan Bergmann <sbergman@redhat.com> wrote:

>>>

>>>On 07/10/2020 18:55, Thomas Rodgers wrote:

>>>>From: Thomas Rodgers <trodgers@redhat.com>

>>>>New ctors and ::view() accessor for -

>>>>  * basic_stingbuf

>>>>  * basic_istringstream

>>>>  * basic_ostringstream

>>>>  * basic_stringstreamm

>>>>New ::get_allocator() accessor for basic_stringbuf.

>>>I found that this <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a0e4d7b44c544c84cffc7ff9c64b6f1af14fb08d> "libstdc++: Implement C++20 features for <sstream>" changed the behavior of

>>>

>>>>$ cat test.cc

>>>>#include <iostream>

>>>>#include <iterator>

>>>>#include <sstream>

>>>>int main() {

>>>> std::stringstream s("a");

>>>> std::istreambuf_iterator<char> i(s);

>>>> if (i != std::istreambuf_iterator<char>()) std::cout << *i << '\n';

>>>>}

>>>>$ g++ -std=c++20 test.cc

>>>>$ ./a.out

>>>

>>>from printing "a" to printing nothing.  (The `i != ...` comparison appears to change i from pointing at "a" to pointing to null, and returns false.)

>>>

>>>I ran into this when building LibreOffice, and I hope test.cc is a faithfully minimized reproducer.  However, I know little about std::istreambuf_iterator, so it may well be that the code isn't even valid.

>>>

>

>I'm testing this patch.


Tested powerpc64le-linux. Pushed now.


>commit 1ca2fe0fc85403c6ea4e0775b5da051ff0eebc96

>Author: Jonathan Wakely <jwakely@redhat.com>

>Date:   Wed Nov 4 21:44:05 2020

>

>    libstdc++: Fix default mode of new basic_stringstream constructor [PR 97719]

>    

>    libstdc++-v3/ChangeLog:

>    

>            PR libstdc++/97719

>            * include/std/sstream (basic_stringstream(string_type&&, openmode)):

>            Fix default argument.

>            * testsuite/27_io/basic_stringstream/cons/char/97719.cc: New test.

>

>diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream

>index 33a00486606c..8acf1eb259ab 100644

>--- a/libstdc++-v3/include/std/sstream

>+++ b/libstdc++-v3/include/std/sstream

>@@ -976,7 +976,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11

> 

>       explicit

>       basic_stringstream(__string_type&& __str,

>-	                 ios_base::openmode __mode = ios_base::out

>+	                 ios_base::openmode __mode = ios_base::in

> 						     | ios_base::out)

>       : __iostream_type(), _M_stringbuf(std::move(__str), __mode)

>       { this->init(std::__addressof(_M_stringbuf)); }

>diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc

>new file mode 100644

>index 000000000000..fa523a803b6d

>--- /dev/null

>+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc

>@@ -0,0 +1,40 @@

>+// Copyright (C) 2020 Free Software Foundation, Inc.

>+//

>+// This file is part of the GNU ISO C++ Library.  This library is free

>+// software; you can redistribute it and/or modify it under the

>+// terms of the GNU General Public License as published by the

>+// Free Software Foundation; either version 3, or (at your option)

>+// any later version.

>+

>+// This library is distributed in the hope that it will be useful,

>+// but WITHOUT ANY WARRANTY; without even the implied warranty of

>+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

>+// GNU General Public License for more details.

>+

>+// You should have received a copy of the GNU General Public License along

>+// with this library; see the file COPYING3.  If not see

>+// <http://www.gnu.org/licenses/>.

>+

>+// { dg-options "-std=gnu++2a" }

>+// { dg-do run { target c++2a } }

>+

>+#include <sstream>

>+#include <iterator>

>+#include <testsuite_hooks.h>

>+

>+void

>+test01()

>+{

>+  // PR libstdc++/97719

>+  std::string str = "a";

>+  std::stringstream s(std::move(str));

>+  std::istreambuf_iterator<char> i(s);

>+  VERIFY( i != std::istreambuf_iterator<char>() );

>+  VERIFY( *i == 'a' );

>+}

>+

>+int

>+main()

>+{

>+  test01();

>+}
Richard Earnshaw via Gcc-patches Nov. 5, 2020, 1:33 p.m. | #6
On 04/11/20 23:41 +0000, Jonathan Wakely wrote:
>On 04/11/20 21:45 +0000, Jonathan Wakely wrote:

>>On 04/11/20 12:43 -0800, Thomas Rodgers wrote:

>>>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97719

>>>

>>>>On Nov 4, 2020, at 11:54 AM, Stephan Bergmann <sbergman@redhat.com> wrote:

>>>>

>>>>On 07/10/2020 18:55, Thomas Rodgers wrote:

>>>>>From: Thomas Rodgers <trodgers@redhat.com>

>>>>>New ctors and ::view() accessor for -

>>>>> * basic_stingbuf

>>>>> * basic_istringstream

>>>>> * basic_ostringstream

>>>>> * basic_stringstreamm

>>>>>New ::get_allocator() accessor for basic_stringbuf.

>>>>I found that this <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a0e4d7b44c544c84cffc7ff9c64b6f1af14fb08d> "libstdc++: Implement C++20 features for <sstream>" changed the behavior of

>>>>

>>>>>$ cat test.cc

>>>>>#include <iostream>

>>>>>#include <iterator>

>>>>>#include <sstream>

>>>>>int main() {

>>>>>std::stringstream s("a");

>>>>>std::istreambuf_iterator<char> i(s);

>>>>>if (i != std::istreambuf_iterator<char>()) std::cout << *i << '\n';

>>>>>}

>>>>>$ g++ -std=c++20 test.cc

>>>>>$ ./a.out

>>>>

>>>>from printing "a" to printing nothing.  (The `i != ...` comparison appears to change i from pointing at "a" to pointing to null, and returns false.)

>>>>

>>>>I ran into this when building LibreOffice, and I hope test.cc is a faithfully minimized reproducer.  However, I know little about std::istreambuf_iterator, so it may well be that the code isn't even valid.

>>>>

>>

>>I'm testing this patch.

>

>Tested powerpc64le-linux. Pushed now.


And this fixes some other bugs in the new constructors.

Tested powerpc64le-linux, pushed to trunk.
commit 432258be4f2cf4f0970f106db319e3dbab4ab13d
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Nov 5 12:16:13 2020

    libstdc++: Fix new <sstream> constructors
    
    - Add a missing 'explicit' to a basic_stringbuf constructor.
    - Set up the get/put area pointers in the constructor from strings using
      different allocator types.
    - Remove public basic_stringbuf::__sv_type alias.
    - Do not construct temporary basic_string objects with a
      default-constructed allocator.
    
    Also, change which basic_string constructor is used, as a minor
    compile-time optimization. Constructing from a basic_string_view
    requires more work from the compiler, so just use a pointer and length.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/sstream (basic_stringbuf(const allocator_type&):
            Add explicit.
            (basic_stringbuf(const basic_string<C,T,SA>&, openmode, const A&)):
            Call _M_stringbuf_init. Construct _M_string from pointer and length
            to avoid constraint checks for string view.
            (basic_stringbuf::view()): Make __sv_type alias local to the
            function.
            (basic_istringstream(const basic_string<C,T,SA>&, openmode, const A&)):
            Pass string to _M_streambuf instead of constructing a temporary
            with the wrong allocator.
            (basic_ostringstream(const basic_string<C,T,SA>&, openmode, const A&)):
            Likewise.
            (basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&)):
            Likewise.
            * src/c++20/sstream-inst.cc: Use string_view and wstring_view
            typedefs in explicit instantiations.
            * testsuite/27_io/basic_istringstream/cons/char/1.cc: Add more
            tests for constructors.
            * testsuite/27_io/basic_ostringstream/cons/char/1.cc: Likewise.
            * testsuite/27_io/basic_stringbuf/cons/char/1.cc: Likewise.
            * testsuite/27_io/basic_stringbuf/cons/char/2.cc: Likewise.
            * testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc: Likewise.
            * testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.
            * testsuite/27_io/basic_stringstream/cons/char/1.cc: Likewise.

diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index 276badfd9657..437e2ba2a5f8 100644
--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -166,8 +166,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 #endif
 
 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
-      using __sv_type = basic_string_view<char_type, traits_type>;
-
+      explicit
       basic_stringbuf(const allocator_type& __a)
       : basic_stringbuf(ios_base::in | std::ios_base::out, __a)
       { }
@@ -185,18 +184,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       { _M_stringbuf_init(__mode); }
 
       template<typename _SAlloc>
-      basic_stringbuf(const basic_string<_CharT, _Traits, _SAlloc>& __s,
-		      const allocator_type& __a)
-      : basic_stringbuf(__s, ios_base::in | std::ios_base::out, __a)
-      { }
+	basic_stringbuf(const basic_string<_CharT, _Traits, _SAlloc>& __s,
+			const allocator_type& __a)
+	: basic_stringbuf(__s, ios_base::in | std::ios_base::out, __a)
+	{ }
 
       template<typename _SAlloc>
-      basic_stringbuf(const basic_string<_CharT, _Traits, _SAlloc>& __s,
-		      ios_base::openmode __mode,
-		      const allocator_type& __a)
-      : __streambuf_type(), _M_mode(__mode),
-      _M_string(static_cast<__sv_type>(__s), __a)
-      { }
+	basic_stringbuf(const basic_string<_CharT, _Traits, _SAlloc>& __s,
+			ios_base::openmode __mode,
+			const allocator_type& __a)
+	: __streambuf_type(), _M_mode(__mode),
+	  _M_string(__s.data(), __s.size(), __a)
+	{ _M_stringbuf_init(__mode); }
 
       template<typename _SAlloc>
 	explicit
@@ -258,9 +257,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       }
 
 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
-      __sv_type
+      basic_string_view<char_type, traits_type>
       view() const noexcept
       {
+	using __sv_type = basic_string_view<char_type, traits_type>;
+
 	if (this->pptr())
 	  {
 	    // The current egptr() may not be the actual string end.
@@ -598,9 +599,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 	basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
 			    ios_base::openmode __mode,
 			    const allocator_type& __a)
-	: __istream_type(),
-	_M_stringbuf(__string_type(__str.data(), __str.size()),
-		     __mode | ios_base::in, __a)
+	: __istream_type(), _M_stringbuf(__str, __mode | ios_base::in, __a)
 	{ this->init(std::__addressof(_M_stringbuf)); }
 
       template<typename _SAlloc>
@@ -796,9 +795,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 	basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
 			    ios_base::openmode __mode,
 			    const allocator_type& __a)
-	: __ostream_type(),
-	_M_stringbuf(__string_type(__str.data(), __str.size()),
-		     __mode | ios_base::out, __a)
+	: __ostream_type(), _M_stringbuf(__str, __mode | ios_base::out, __a)
 	{ this->init(std::__addressof(_M_stringbuf)); }
 
       template<typename _SAlloc>
@@ -991,8 +988,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 	basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
 			   ios_base::openmode __mode,
 			   const allocator_type& __a)
-	: __iostream_type(),
-	_M_stringbuf(__string_type(__str.data(), __str.size()), __mode, __a)
+	: __iostream_type(), _M_stringbuf(__str, __mode, __a)
 	{ this->init(std::__addressof(_M_stringbuf)); }
 
       template<typename _SAlloc>
diff --git a/libstdc++-v3/src/c++20/sstream-inst.cc b/libstdc++-v3/src/c++20/sstream-inst.cc
index 8c6840115c50..ada3eabac1f5 100644
--- a/libstdc++-v3/src/c++20/sstream-inst.cc
+++ b/libstdc++-v3/src/c++20/sstream-inst.cc
@@ -43,7 +43,7 @@ template basic_stringbuf<char>::basic_stringbuf(basic_stringbuf&&,
 						const allocator_type&);
 template basic_stringbuf<char>::allocator_type
 basic_stringbuf<char>::get_allocator() const noexcept;
-template basic_stringbuf<char>::__sv_type
+template string_view
 basic_stringbuf<char>::view() const noexcept;
 
 template basic_istringstream<char>::basic_istringstream(ios_base::openmode,
@@ -68,8 +68,6 @@ template string_view
 basic_stringstream<char>::view() const noexcept;
 
 #ifdef _GLIBCXX_USE_WCHAR_T
-using wsv_type = basic_string_view<wchar_t>;
-
 template basic_stringbuf<wchar_t>::basic_stringbuf(const allocator_type&);
 template basic_stringbuf<wchar_t>::basic_stringbuf(ios_base::openmode,
 						   const allocator_type&);
@@ -80,7 +78,7 @@ template basic_stringbuf<wchar_t>::basic_stringbuf(basic_stringbuf&&,
 template basic_stringbuf<wchar_t>::allocator_type
 basic_stringbuf<wchar_t>::get_allocator() const noexcept;
 
-template basic_istringstream<wchar_t>::__stringbuf_type::__sv_type
+template wstring_view
 basic_stringbuf<wchar_t>::view() const noexcept;
 
 template basic_istringstream<wchar_t>::basic_istringstream(ios_base::openmode,
diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
index 496aa6963e0b..6584b88193d3 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
@@ -33,7 +33,7 @@ test01()
   std::istringstream stm(std::ios_base::in, a);
 }
 
-auto const cstr = "This is a test";
+auto const cstr = "This is a test string";
 
 void
 test02()
@@ -75,11 +75,44 @@ test03()
   }
 }
 
+// A minimal allocator with no default constructor
+template<typename T>
+  struct NoDefaultCons : __gnu_test::SimpleAllocator<T>
+  {
+    using __gnu_test::SimpleAllocator<T>::SimpleAllocator;
+
+    NoDefaultCons() = delete;
+
+    NoDefaultCons(int) { }
+  };
+
+void
+test04()
+{
+  using sstream = std::basic_istringstream<char, std::char_traits<char>,
+					   NoDefaultCons<char>>;
+
+  NoDefaultCons<char> a(1);
+  const std::string str(cstr);
+
+  sstream ss1(str, a);
+  VERIFY( ss1.str() == cstr );
+  VERIFY( ss1.get() == cstr[0] );
+
+  sstream ss2(str, std::ios::out, a);
+  VERIFY( ss2.str() == cstr );
+  VERIFY( ss2.get() == cstr[0] );
+
+  sstream ss3(std::string(str), std::ios::out, a);
+  VERIFY( ss3.str() == cstr );
+  VERIFY( ss3.get() == cstr[0] );
+}
+
 int
 main()
 {
   test01();
   test02();
   test03();
-  return 0;
+  test04();
 }
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc
index cba69f80931a..885949caf002 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc
@@ -33,7 +33,7 @@ test01()
   std::ostringstream stm(std::ios_base::in, a);
 }
 
-auto const cstr = "This is a test";
+auto const cstr = "This is a test string";
 
 void
 test02()
@@ -75,11 +75,45 @@ test03()
   }
 }
 
+// A minimal allocator with no default constructor
+template<typename T>
+  struct NoDefaultCons : __gnu_test::SimpleAllocator<T>
+  {
+    using __gnu_test::SimpleAllocator<T>::SimpleAllocator;
+
+    NoDefaultCons() = delete;
+
+    NoDefaultCons(int) { }
+  };
+
+void
+test04()
+{
+  using sstream = std::basic_ostringstream<char, std::char_traits<char>,
+					   NoDefaultCons<char>>;
+
+  NoDefaultCons<char> a(1);
+  const std::string str(cstr);
+
+  sstream ss1(str, a);
+  VERIFY( ss1.str() == cstr );
+
+  sstream ss2(str, std::ios::in, a);
+  VERIFY( ss2.str() == cstr );
+  VERIFY( bool(ss2 << "That") );
+  VERIFY( ss2.str() == "That is a test string" );
+
+  sstream ss3(std::string(str), std::ios::ate, a);
+  VERIFY( ss3.str() == cstr );
+  VERIFY( bool(ss3 << "y thing") );
+  VERIFY( ss3.str() == "This is a test stringy thing" );
+}
+
 int
 main()
 {
   test01();
   test02();
   test03();
-  return 0;
+  test04();
 }
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc
index 0e9649798f88..bd17e6ddc9e3 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc
@@ -17,7 +17,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+// C++03 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
 
 #include <sstream>
 #include <testsuite_hooks.h>
@@ -30,8 +30,41 @@ void test01()
   VERIFY( sbuf.check_pointers() );
 }
 
-int main() 
+void test02()
+{
+  std::stringbuf sbuf;
+  VERIFY( sbuf.str().empty() );
+
+  std::stringbuf sbuf1(std::ios::in);
+  VERIFY( sbuf1.str().empty() );
+
+  const std::string str = "This is my boomstick!";
+
+  std::stringbuf sbuf2(str);
+  VERIFY( sbuf2.str() == str );
+
+  std::stringbuf sbuf3(str, std::ios::in);
+  VERIFY( sbuf3.str() == str );
+  VERIFY( sbuf3.sgetc() == str[0] );
+  VERIFY( sbuf3.sputc('X') == std::stringbuf::traits_type::eof() );
+
+  std::stringbuf sbuf4(str, std::ios::out);
+  VERIFY( sbuf4.str() == str );
+  VERIFY( sbuf4.sputc('Y') == 'Y' );
+  VERIFY( sbuf4.sgetc() == std::stringbuf::traits_type::eof() );
+
+#if __cplusplus >= 201103L
+  static_assert( ! std::is_convertible<std::ios::openmode, std::stringbuf>(),
+		  "stringbuf(ios::openmode) is explicit");
+
+  static_assert( ! std::is_convertible<const std::string&, std::stringbuf>(),
+		  "stringbuf(string, ios::openmode) is explicit");
+#endif
+}
+
+int main()
 {
   test01();
+  test02();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc
index ce669358c850..c72ca5c7c84d 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+// C++20 29.8.2.2  basic_stringbuf constructors  [stringbuf.cons]
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
@@ -26,13 +26,24 @@
 #include <testsuite_allocator.h>
 #include <testsuite_hooks.h>
 
+template<typename Alloc, typename C = typename Alloc::value_type>
+  using stringbuf_with_alloc
+    = std::basic_stringbuf<C, std::char_traits<C>, Alloc>;
+
 void
 test01()
 {
+  // Test C++20 constructors taking an allocator but no string.
+
+  static_assert(!std::is_convertible_v<std::allocator<char>, std::stringbuf>,
+      "stringbuf(const allocator<char>&) is explicit");
+
   {
     using alloc_type = __gnu_test::uneq_allocator<char>;
-    using sbuf_t = std::basic_stringbuf<char, std::char_traits<char>,
-						alloc_type>;
+    using sbuf_t = stringbuf_with_alloc<alloc_type>;
+
+    static_assert(!std::is_convertible_v<const alloc_type&, sbuf_t>,
+	"basic_stringbuf(const basic_stringbuf::allocator_type&) is explicit");
 
     alloc_type aa;
     sbuf_t sbuf1(aa);
@@ -48,29 +59,64 @@ test01()
   std::stringbuf::allocator_type a;
   {
     std::stringbuf sbuf(std::ios_base::in, a);
+    VERIFY( sbuf.str().empty() );
+
+    std::stringbuf sbuf2 = {std::ios_base::in, a}; // non-explicit ctor
   }
 
   {
     std::stringbuf sbuf(a);
+    VERIFY( sbuf.str().empty() );
   }
 }
 
-auto const cstr = "This is a test";
+auto const cstr = "This is a test string";
 
 void
 test02()
 {
+  // Test C++20 constructor taking an rvalue string
+
+  static_assert(!std::is_convertible_v<std::string, std::stringbuf>,
+      "stringbuf(string&&, ios::openmode) is explicit");
+
   std::string s1(cstr);
-  std::stringbuf sbuf(std::move(s1));
+  std::stringbuf sbuf1(std::move(s1));
   VERIFY( s1.empty() );
+  VERIFY( sbuf1.str() == cstr );
+  VERIFY( sbuf1.sgetc() == cstr[0] );
 
   std::string s2(cstr);
-  VERIFY( sbuf.str() == s2 );
+  std::stringbuf sbuf2(std::move(s2), std::ios_base::in);
+  VERIFY( s2.empty() );
+  VERIFY( sbuf2.str() == cstr );
+  VERIFY( sbuf2.sgetc() == cstr[0] );
+  VERIFY( sbuf2.sputc('X') == std::stringbuf::traits_type::eof() );
+
+  std::string s3(cstr);
+  std::stringbuf sbuf3(std::move(s3), std::ios_base::out);
+  VERIFY( s3.empty() );
+  VERIFY( sbuf3.str() == cstr );
+  VERIFY( sbuf3.sputc('Y') == 'Y' );
+  VERIFY( sbuf3.sgetc() == std::stringbuf::traits_type::eof() );
 }
 
+// A minimal allocator with no default constructor
+template<typename T>
+  struct NoDefaultCons : __gnu_test::SimpleAllocator<T>
+  {
+    using __gnu_test::SimpleAllocator<T>::SimpleAllocator;
+
+    NoDefaultCons() = delete;
+
+    NoDefaultCons(int) { }
+  };
+
 void
 test03()
 {
+  // Test C++20 constructors taking strings using different allocators
+
   using alloc_type = __gnu_test::tracker_allocator<char>;
   using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
 
@@ -78,28 +124,92 @@ test03()
   str_type s1(cstr);
 
   {
+    // basic_stringbuf(const basic_string<char, traits_type, SAlloc>&,
+    //                 ios_base::openmode,
+    //                 const allocator_type&)
+
     std::stringbuf::allocator_type a;
-    std::stringbuf sbuf(s1, mode, a);
+    std::stringbuf sbuf = {s1, mode, a}; // ={} checks for non-explicit ctor
     std::string s2(cstr);
     VERIFY( sbuf.str() == s2 );
+
+    std::stringbuf sbuf2 = {std::move(s1), std::ios::in, a};
+    VERIFY( sbuf2.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf2.sgetc() == s1[0] );
+    VERIFY( sbuf2.sputc('X') == std::stringbuf::traits_type::eof() );
+
+    std::stringbuf sbuf3 = {std::move(s1), std::ios::out, a};
+    VERIFY( sbuf3.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf3.sputc('X') == 'X' );
+    VERIFY( sbuf3.sgetc() == std::stringbuf::traits_type::eof() );
   }
 
   {
+    // explicit
+    // basic_stringbuf(const basic_string<char, traits_type, SAlloc>&,
+    //                 ios_base::openmode)
+
     std::stringbuf sbuf(s1, mode);
     std::string s2(cstr);
     VERIFY( sbuf.str() == s2 );
+
+    std::stringbuf sbuf2(std::move(s1), std::ios::in);
+    VERIFY( sbuf2.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf2.sgetc() == s1[0] );
+    VERIFY( sbuf2.sputc('X') == std::stringbuf::traits_type::eof() );
+
+    std::stringbuf sbuf3(std::move(s1), std::ios::out);
+    VERIFY( sbuf3.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf3.sputc('X') == 'X' );
+    VERIFY( sbuf3.sgetc() == std::stringbuf::traits_type::eof() );
   }
 
   {
+    // explicit
+    // basic_stringbuf(const basic_string<char, traits_type, SAlloc>&,
+    //                 ios_base::openmode = ios_base::in|ios_base::out)
+
+    static_assert( ! std::is_convertible_v<str_type, std::stringbuf>,
+	"stringbuf(const basic_string<char, traits_type, SAlloc>&, openmode)"
+	" is explicit");
+
     std::stringbuf sbuf(s1);
     std::string s2(cstr);
     VERIFY( sbuf.str() == s2 );
+
+    std::stringbuf sbuf2(std::move(s1));
+    VERIFY( sbuf2.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf2.sgetc() == s1[0] );
+  }
+
+  {
+    NoDefaultCons<char> a(1);
+    stringbuf_with_alloc<NoDefaultCons<char>> sbuf1(s1, a);
+    VERIFY( sbuf1.str() == cstr );
+    VERIFY( sbuf1.sgetc() == s1[0] );
+
+    stringbuf_with_alloc<NoDefaultCons<char>> sbuf2(s1, std::ios::in, a);
+    VERIFY( sbuf2.str() == cstr );
+    VERIFY( sbuf2.sgetc() == s1[0] );
+    VERIFY( sbuf2.sputc('X') == std::stringbuf::traits_type::eof() );
+
+    stringbuf_with_alloc<NoDefaultCons<char>> sbuf3(s1, std::ios::out, a);
+    VERIFY( sbuf3.str() == cstr );
+    VERIFY( sbuf3.sputc('X') == 'X' );
+    VERIFY( sbuf3.sgetc() == std::stringbuf::traits_type::eof() );
   }
 }
 
 void
 test04()
 {
+  // Test C++20 allocator-extended move constructor
+
   std::stringbuf sbuf1(cstr);
 
   std::stringbuf::allocator_type a;
@@ -117,5 +227,4 @@ main()
   test02();
   test03();
   test04();
-  return 0;
 }
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc
index 7d51744fd8d2..4e3a2a9631d8 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc
@@ -17,7 +17,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+// C++03 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
 
 #include <sstream>
 #include <testsuite_hooks.h>
@@ -30,8 +30,41 @@ void test01()
   VERIFY( sbuf.check_pointers() );
 }
 
-int main() 
+void test02()
+{
+  std::wstringbuf sbuf;
+  VERIFY( sbuf.str().empty() );
+
+  std::wstringbuf sbuf1(std::wios::in);
+  VERIFY( sbuf1.str().empty() );
+
+  const std::wstring str = L"This is my boomstick!";
+
+  std::wstringbuf sbuf2(str);
+  VERIFY( sbuf2.str() == str );
+
+  std::wstringbuf sbuf3(str, std::wios::in);
+  VERIFY( sbuf3.str() == str );
+  VERIFY( sbuf3.sgetc() == str[0] );
+  VERIFY( sbuf3.sputc(L'X') == std::wstringbuf::traits_type::eof() );
+
+  std::wstringbuf sbuf4(str, std::wios::out);
+  VERIFY( sbuf4.str() == str );
+  VERIFY( sbuf4.sputc(L'Y') == L'Y' );
+  VERIFY( sbuf4.sgetc() == std::wstringbuf::traits_type::eof() );
+
+#if __cplusplus >= 201103L
+  static_assert( ! std::is_convertible<std::wios::openmode, std::wstringbuf>(),
+		  "wstringbuf(wios::openmode) is explicit");
+
+  static_assert( ! std::is_convertible<const std::wstring&, std::wstringbuf>(),
+		  "wstringbuf(wstring, wios::openmode) is explicit");
+#endif
+}
+
+int main()
 {
   test01();
+  test02();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc
index e05acc421659..4fbbbf39ad39 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+// C++20 29.8.2.2  basic_stringbuf constructors  [stringbuf.cons]
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
@@ -26,35 +26,97 @@
 #include <testsuite_allocator.h>
 #include <testsuite_hooks.h>
 
+template<typename Alloc, typename C = typename Alloc::value_type>
+  using stringbuf_with_alloc
+    = std::basic_stringbuf<C, std::char_traits<C>, Alloc>;
+
 void
 test01()
 {
+  // Test C++20 constructors taking an allocator but no string.
+
+  static_assert(!std::is_convertible_v<std::allocator<wchar_t>, std::wstringbuf>,
+      "wstringbuf(const allocator<wchar_t>&) is explicit");
+
+  {
+    using alloc_type = __gnu_test::uneq_allocator<wchar_t>;
+    using sbuf_t = stringbuf_with_alloc<alloc_type>;
+
+    static_assert(!std::is_convertible_v<const alloc_type&, sbuf_t>,
+	"basic_stringbuf(const basic_stringbuf::allocator_type&) is explicit");
+
+    alloc_type aa;
+    sbuf_t sbuf1(aa);
+    VERIFY( aa == sbuf1.get_allocator() );
+
+    alloc_type aaa(42);
+    sbuf_t sbuf2(aaa);
+    VERIFY( aaa == sbuf2.get_allocator() );
+
+    VERIFY( sbuf1.get_allocator() != sbuf2.get_allocator() );
+  }
+
   std::wstringbuf::allocator_type a;
   {
     std::wstringbuf sbuf(std::ios_base::in, a);
+    VERIFY( sbuf.str().empty() );
+
+    std::wstringbuf sbuf2 = {std::ios_base::in, a}; // non-explicit ctor
   }
 
   {
     std::wstringbuf sbuf(a);
+    VERIFY( sbuf.str().empty() );
   }
 }
 
-auto const cstr = L"This is a test";
+auto const cstr = L"This is a test string";
 
 void
 test02()
 {
+  // Test C++20 constructor taking an rvalue string
+
+  static_assert(!std::is_convertible_v<std::wstring, std::wstringbuf>,
+      "wstringbuf(wstring&&, ios::openmode) is explicit");
+
   std::wstring s1(cstr);
-  std::wstringbuf sbuf(std::move(s1));
+  std::wstringbuf sbuf1(std::move(s1));
   VERIFY( s1.empty() );
+  VERIFY( sbuf1.str() == cstr );
+  VERIFY( sbuf1.sgetc() == cstr[0] );
 
   std::wstring s2(cstr);
-  VERIFY( sbuf.str() == s2 );
+  std::wstringbuf sbuf2(std::move(s2), std::ios_base::in);
+  VERIFY( s2.empty() );
+  VERIFY( sbuf2.str() == cstr );
+  VERIFY( sbuf2.sgetc() == cstr[0] );
+  VERIFY( sbuf2.sputc(L'X') == std::wstringbuf::traits_type::eof() );
+
+  std::wstring s3(cstr);
+  std::wstringbuf sbuf3(std::move(s3), std::ios_base::out);
+  VERIFY( s3.empty() );
+  VERIFY( sbuf3.str() == cstr );
+  VERIFY( sbuf3.sputc(L'Y') == L'Y' );
+  VERIFY( sbuf3.sgetc() == std::wstringbuf::traits_type::eof() );
 }
 
+// A minimal allocator with no default constructor
+template<typename T>
+  struct NoDefaultCons : __gnu_test::SimpleAllocator<T>
+  {
+    using __gnu_test::SimpleAllocator<T>::SimpleAllocator;
+
+    NoDefaultCons() = delete;
+
+    NoDefaultCons(int) { }
+  };
+
 void
 test03()
 {
+  // Test C++20 constructors taking strings using different allocators
+
   using alloc_type = __gnu_test::tracker_allocator<wchar_t>;
   using str_type = std::basic_string<wchar_t, std::char_traits<wchar_t>, alloc_type>;
 
@@ -62,28 +124,92 @@ test03()
   str_type s1(cstr);
 
   {
+    // basic_stringbuf(const basic_string<wchar_t, traits_type, SAlloc>&,
+    //                 ios_base::openmode,
+    //                 const allocator_type&)
+
     std::wstringbuf::allocator_type a;
-    std::wstringbuf sbuf(s1, mode, a);
+    std::wstringbuf sbuf = {s1, mode, a}; // ={} checks for non-explicit ctor
     std::wstring s2(cstr);
     VERIFY( sbuf.str() == s2 );
+
+    std::wstringbuf sbuf2 = {std::move(s1), std::ios::in, a};
+    VERIFY( sbuf2.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf2.sgetc() == s1[0] );
+    VERIFY( sbuf2.sputc(L'X') == std::wstringbuf::traits_type::eof() );
+
+    std::wstringbuf sbuf3 = {std::move(s1), std::ios::out, a};
+    VERIFY( sbuf3.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf3.sputc(L'X') == L'X' );
+    VERIFY( sbuf3.sgetc() == std::wstringbuf::traits_type::eof() );
   }
 
   {
+    // explicit
+    // basic_stringbuf(const basic_string<wchar_t, traits_type, SAlloc>&,
+    //                 ios_base::openmode)
+
     std::wstringbuf sbuf(s1, mode);
     std::wstring s2(cstr);
     VERIFY( sbuf.str() == s2 );
+
+    std::wstringbuf sbuf2(std::move(s1), std::ios::in);
+    VERIFY( sbuf2.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf2.sgetc() == s1[0] );
+    VERIFY( sbuf2.sputc(L'X') == std::wstringbuf::traits_type::eof() );
+
+    std::wstringbuf sbuf3(std::move(s1), std::ios::out);
+    VERIFY( sbuf3.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf3.sputc(L'X') == L'X' );
+    VERIFY( sbuf3.sgetc() == std::wstringbuf::traits_type::eof() );
   }
 
   {
+    // explicit
+    // basic_stringbuf(const basic_string<wchar_t, traits_type, SAlloc>&,
+    //                 ios_base::openmode = ios_base::in|ios_base::out)
+
+    static_assert( ! std::is_convertible_v<str_type, std::wstringbuf>,
+	"wstringbuf(const basic_string<wchar_t, traits_type, SAlloc>&,"
+		  " openmode) is explicit");
+
     std::wstringbuf sbuf(s1);
     std::wstring s2(cstr);
     VERIFY( sbuf.str() == s2 );
+
+    std::wstringbuf sbuf2(std::move(s1));
+    VERIFY( sbuf2.str() == s2 );
+    VERIFY( s1 == cstr ); // did not move from std::move(s1)
+    VERIFY( sbuf2.sgetc() == s1[0] );
+  }
+
+  {
+    NoDefaultCons<wchar_t> a(1);
+    stringbuf_with_alloc<NoDefaultCons<wchar_t>> sbuf1(s1, a);
+    VERIFY( sbuf1.str() == cstr );
+    VERIFY( sbuf1.sgetc() == s1[0] );
+
+    stringbuf_with_alloc<NoDefaultCons<wchar_t>> sbuf2(s1, std::ios::in, a);
+    VERIFY( sbuf2.str() == cstr );
+    VERIFY( sbuf2.sgetc() == s1[0] );
+    VERIFY( sbuf2.sputc(L'X') == std::wstringbuf::traits_type::eof() );
+
+    stringbuf_with_alloc<NoDefaultCons<wchar_t>> sbuf3(s1, std::ios::out, a);
+    VERIFY( sbuf3.str() == cstr );
+    VERIFY( sbuf3.sputc(L'X') == L'X' );
+    VERIFY( sbuf3.sgetc() == std::wstringbuf::traits_type::eof() );
   }
 }
 
 void
 test04()
 {
+  // Test C++20 allocator-extended move constructor
+
   std::wstringbuf sbuf1(cstr);
 
   std::wstringbuf::allocator_type a;
@@ -101,5 +227,4 @@ main()
   test02();
   test03();
   test04();
-  return 0;
 }
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc
index 83a3374b3cdb..33f2953a6513 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc
@@ -33,7 +33,7 @@ test01()
   std::stringstream stm(std::ios_base::in, a);
 }
 
-auto const cstr = "This is a test";
+auto const cstr = "This is a test string";
 
 void
 test02()
@@ -57,29 +57,64 @@ test03()
 
   {
     std::stringstream::allocator_type a;
-    std::stringstream sbuf(s1, mode, a);
+    std::stringstream ss(s1, mode, a);
     std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    VERIFY( ss.str() == s2 );
   }
 
   {
-    std::stringstream sbuf(s1, mode);
+    std::stringstream ss(s1, mode);
     std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    VERIFY( ss.str() == s2 );
   }
 
   {
-    std::stringstream sbuf(s1);
+    std::stringstream ss(s1);
     std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    VERIFY( ss.str() == s2 );
   }
 }
 
+// A minimal allocator with no default constructor
+template<typename T>
+  struct NoDefaultCons : __gnu_test::SimpleAllocator<T>
+  {
+    using __gnu_test::SimpleAllocator<T>::SimpleAllocator;
+
+    NoDefaultCons() = delete;
+
+    NoDefaultCons(int) { }
+  };
+
+void
+test04()
+{
+  using sstream = std::basic_stringstream<char, std::char_traits<char>,
+					  NoDefaultCons<char>>;
+
+  NoDefaultCons<char> a(1);
+  const std::string str(cstr);
+
+  sstream ss1(str, a);
+  VERIFY( ss1.str() == cstr );
+  VERIFY( ss1.get() == cstr[0] );
+
+  sstream ss2(str, std::ios::in, a);
+  VERIFY( ss2.str() == cstr );
+  VERIFY( ss2.get() == cstr[0] );
+  VERIFY( !bool(ss2 << 1) );
+
+  sstream ss3(std::string(str), std::ios::out, a);
+  VERIFY( ss3.str() == cstr );
+  VERIFY( bool(ss3 << 1) );
+  VERIFY( ss3.get() == std::wstringbuf::traits_type::eof() );
+}
+
 int
 main()
 {
   test01();
   test02();
   test03();
-  return 0;
+  test04();
 }

Patch

diff --git a/.topdeps b/.topdeps
new file mode 100644
index 00000000000..1f7391f92b6
--- /dev/null
+++ b/.topdeps
@@ -0,0 +1 @@ 
+master
diff --git a/.topmsg b/.topmsg
new file mode 100644
index 00000000000..0c035ed2f0c
--- /dev/null
+++ b/.topmsg
@@ -0,0 +1,2 @@ 
+From: Thomas Rodgers <trodgers@redhat.com>
+Subject: [PATCH] t/trodgers/c2a_sstream
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 133125ec4fa..b9452dd74cd 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -49,7 +49,7 @@  AC_DEFUN([GLIBCXX_CONFIGURE], [
   # Keep these sync'd with the list in Makefile.am.  The first provides an
   # expandable list at autoconf time; the second provides an expandable list
   # (i.e., shell variable) at configure time.
-  m4_define([glibcxx_SUBDIRS],[include libsupc++ src src/c++98 src/c++11 src/c++17 src/filesystem doc po testsuite python])
+  m4_define([glibcxx_SUBDIRS],[include libsupc++ src src/c++98 src/c++11 src/c++17 src/c++20 src/filesystem doc po testsuite python])
   SUBDIRS='glibcxx_SUBDIRS'
 
   # These need to be absolute paths, yet at the same time need to
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 87a48a21f53..3239bb1a53d 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -2322,6 +2322,66 @@  GLIBCXX_3.4.29 {
     # std::__atomic_futex_unsigned_base::_M_futex_wait_until_steady
     _ZNSt28__atomic_futex_unsigned_base26_M_futex_wait_until_steady*;
 
+    # basic_stringbuf::basic_stringbuf(allocator const&)
+    _ZNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEC1ERKS3_;
+    _ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEEC1ERKS3_;
+
+    # basic_stringbuf::basic_stringbuf(ios_base::openmode, allocator const&)
+    _ZNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEC1ESt13_Ios_OpenmodeRKS3;
+    _ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEEC1ESt13_Ios_OpenmodeRKS3;
+
+    # basic_stringbuf::basic_stringbuf(basic_string&&, ios_base::openmode)
+    _ZNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEC1EONS_12basic_stringIcS2_S3_EESt13_Ios_Openmode;
+    _ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEEC1EONS_12basic_stringIwS2_S3_EESt13_Ios_Openmode;
+
+    # basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&)
+    _ZNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEC1EOS4_RKS3_;
+    _ZNSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEEC1EOS4_RKS3_;
+
+    # basic_stringbuf::get_allocator()
+    _ZNKSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEE13get_allocatorEv;
+    _ZNKSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEE13get_allocatorEv;
+
+    # basic_stringbuf::view()
+    _ZNKSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEE4viewEv;
+    _ZNKSt7__cxx1115basic_stringbufIwSt11char_traitsIwESaIwEE4viewEv;
+
+    # basic_istringstream::basic_istringstream(basic_string&&, ios_base::openmode)
+    _ZNSt7__cxx1119basic_istringstreamIcSt11char_traitsIcESaIcEEC1EONS_12basic_stringIcS2_S3_EESt13_Ios_Openmode;
+    _ZNSt7__cxx1119basic_istringstreamIwSt11char_traitsIwESaIwEEC1EONS_12basic_stringIwS2_S3_EESt13_Ios_Openmode;
+
+    # basic_istringstream::basic_istringstream(ios_base::openmode, allocator const&)
+    _ZNSt7__cxx1119basic_istringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_OpenmodeRKS3_;
+    _ZNSt7__cxx1119basic_istringstreamIwSt11char_traitsIwESaIwEEC1ESt13_Ios_OpenmodeRKS3_;
+
+    # basic_istringstream::view()
+    _ZNKSt7__cxx1119basic_istringstreamIcSt11char_traitsIcESaIcEE4viewEv;
+    _ZNKSt7__cxx1119basic_istringstreamIwSt11char_traitsIwESaIwEE4viewEv;
+
+    # basic_ostringstream::basic_ostringstream(basic_string&&, ios_base::openmode)
+    _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1EONS_12basic_stringIcS2_S3_EESt13_Ios_Openmode;
+    _ZNSt7__cxx1119basic_ostringstreamIwSt11char_traitsIwESaIwEEC1EONS_12basic_stringIwS2_S3_EESt13_Ios_Openmode;
+
+    # basic_ostringstream::basic_ostringstream(ios_base::openmode, allocator const&)
+    _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_OpenmodeRKS3_;
+    _ZNSt7__cxx1119basic_ostringstreamIwSt11char_traitsIwESaIwEEC1ESt13_Ios_OpenmodeRKS3_;
+
+    # basic_ostringstream::view()
+    _ZNKSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEE4viewEv;
+    _ZNKSt7__cxx1119basic_ostringstreamIwSt11char_traitsIwESaIwEE4viewEv;
+
+    # basic_stringstream::basic_stringstream(basic_string&&, ios_base::openmode)
+    _ZNSt7__cxx1119basic_stringstreamIcSt11char_traitsIcESaIcEEC1EONS_12basic_stringIcS2_S3_EESt13_Ios_Openmode;
+    _ZNSt7__cxx1119basic_stringstreamIwSt11char_traitsIwESaIwEEC1EONS_12basic_stringIwS2_S3_EESt13_Ios_Openmode;
+
+    # basic_stringstream::basic_stringstream(ios_base::openmode, allocator const&)
+    _ZNSt7__cxx1119basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_OpenmodeRKS3_;
+    _ZNSt7__cxx1119basic_stringstreamIwSt11char_traitsIwESaIwEEC1ESt13_Ios_OpenmodeRKS3_;
+
+    # basic_stringstream::view()
+    _ZNKSt7__cxx1119basic_stringstreamIcSt11char_traitsIcESaIcEE4viewEv;
+    _ZNKSt7__cxx1119basic_stringstreamIwSt11char_traitsIwESaIwEE4viewEv;
+
 } GLIBCXX_3.4.28;
 
 # Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 7abf1b1ccc1..eecf63f4a59 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -5418,7 +5418,7 @@  $as_echo "$ac_cv_path_EGREP" >&6; }
   # expandable list at autoconf time; the second provides an expandable list
   # (i.e., shell variable) at configure time.
 
-  SUBDIRS='include libsupc++ src src/c++98 src/c++11 src/c++17 src/filesystem doc po testsuite python'
+  SUBDIRS='include libsupc++ src src/c++98 src/c++11 src/c++17 src/c++20 src/filesystem doc po testsuite python'
 
   # These need to be absolute paths, yet at the same time need to
   # canonicalize only relative paths, because then amd will not unmount
@@ -78394,7 +78394,7 @@  ac_config_files="$ac_config_files doc/xsl/customization.xsl"
 # append it here.  Only modify Makefiles that have just been created.
 #
 # Also, get rid of this simulated-VPATH thing that automake does.
-ac_config_files="$ac_config_files include/Makefile libsupc++/Makefile src/Makefile src/c++98/Makefile src/c++11/Makefile src/c++17/Makefile src/filesystem/Makefile doc/Makefile po/Makefile testsuite/Makefile python/Makefile"
+ac_config_files="$ac_config_files include/Makefile libsupc++/Makefile src/Makefile src/c++98/Makefile src/c++11/Makefile src/c++17/Makefile src/c++20/Makefile src/filesystem/Makefile doc/Makefile po/Makefile testsuite/Makefile python/Makefile"
 
 
 ac_config_commands="$ac_config_commands generate-headers"
@@ -79650,6 +79650,7 @@  do
     "src/c++98/Makefile") CONFIG_FILES="$CONFIG_FILES src/c++98/Makefile" ;;
     "src/c++11/Makefile") CONFIG_FILES="$CONFIG_FILES src/c++11/Makefile" ;;
     "src/c++17/Makefile") CONFIG_FILES="$CONFIG_FILES src/c++17/Makefile" ;;
+    "src/c++20/Makefile") CONFIG_FILES="$CONFIG_FILES src/c++20/Makefile" ;;
     "src/filesystem/Makefile") CONFIG_FILES="$CONFIG_FILES src/filesystem/Makefile" ;;
     "doc/Makefile") CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;;
     "po/Makefile") CONFIG_FILES="$CONFIG_FILES po/Makefile" ;;
@@ -81500,6 +81501,17 @@  _EOF
  ;;
     "src/c++17/Makefile":F) cat > vpsed$$ << \_EOF
 s!`test -f '$<' || echo '$(srcdir)/'`!!
+_EOF
+   sed -f vpsed$$ $ac_file > tmp$$
+   mv tmp$$ $ac_file
+   rm vpsed$$
+   echo 'MULTISUBDIR =' >> $ac_file
+   ml_norecursion=yes
+   . ${multi_basedir}/config-ml.in
+   { ml_norecursion=; unset ml_norecursion;}
+ ;;
+    "src/c++20/Makefile":F) cat > vpsed$$ << \_EOF
+s!`test -f '$<' || echo '$(srcdir)/'`!!
 _EOF
    sed -f vpsed$$ $ac_file > tmp$$
    mv tmp$$ $ac_file
diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index 9cca54d17d1..fb0fb9f8beb 100644
--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -165,6 +165,56 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       }
 #endif
 
+#if __cplusplus > 201703L
+      basic_stringbuf(const allocator_type& __a)
+      : basic_stringbuf(ios_base::in | std::ios_base::out, __a)
+      { }
+
+      basic_stringbuf(ios_base::openmode __mode,
+		      const allocator_type& __a)
+      : __streambuf_type(), _M_mode(__mode), _M_string(__a)
+      { }
+
+      explicit
+      basic_stringbuf(__string_type&& __s,
+	              ios_base::openmode __mode = ios_base::in
+						  | ios_base::out )
+      : __streambuf_type(), _M_mode(__mode), _M_string(move(__s))
+      { }
+
+      template<typename _SAlloc>
+      basic_stringbuf(const basic_string<_CharT, _Traits, _SAlloc>& __s,
+		      const allocator_type& __a )
+      : basic_stringbuf(__s, ios_base::in | std::ios_base::out, __a )
+      { }
+
+      using __sv_type = basic_string_view<char_type, traits_type>;
+
+      template<typename _SAlloc>
+      basic_stringbuf(const basic_string<_CharT, _Traits, _SAlloc>& __s,
+		      ios_base::openmode __mode,
+		      const allocator_type& __a)
+      : __streambuf_type(), _M_mode(__mode),
+      _M_string(static_cast<__sv_type>(__s), __a)
+      { }
+
+      template<typename _SAlloc>
+	explicit
+	basic_stringbuf(const basic_string<_CharT, _Traits, _SAlloc>& __s,
+	                ios_base::openmode __mode = ios_base::in
+						    | ios_base::out)
+	: basic_stringbuf(__s, __mode, allocator_type{})
+	{ }
+
+      basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a)
+      : basic_stringbuf(std::move(__rhs), __a, __xfer_bufptrs(__rhs, this))
+      { __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0); }
+
+      allocator_type get_allocator() const noexcept
+      { return _M_string.get_allocator(); }
+
+#endif
+
       // Get and set:
       /**
        *  @brief  Copying out the string buffer.
@@ -207,6 +257,24 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
 	_M_stringbuf_init(_M_mode);
       }
 
+#if __cplusplus > 201703L
+      __sv_type
+      view() const noexcept
+      {
+	if (this->pptr())
+	  {
+	    // The current egptr() may not be the actual string end.
+	    if (this->pptr() > this->egptr())
+	      return __sv_type(this->pbase(), this->pptr());
+	    else
+	      return __sv_type(this->pbase(), this->egptr());
+	  }
+	else
+	  return static_cast<__sv_type>(_M_string);
+      }
+
+#endif
+
     protected:
       // Common initialization code goes here.
       void
@@ -369,6 +437,16 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
       _M_mode(__rhs._M_mode), _M_string(std::move(__rhs._M_string))
       { }
+
+#if __cplusplus > 201703L
+      // The move constructor initializes an __xfer_bufptrs temporary then
+      // delegates to this constructor to performs moves during its lifetime.
+      basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a,
+		      __xfer_bufptrs&&)
+      : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
+      _M_mode(__rhs._M_mode), _M_string(std::move(__rhs._M_string), __a)
+      { }
+#endif
 #endif
     };
 
@@ -500,6 +578,40 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       }
 #endif
 
+#if __cplusplus > 201703L
+      basic_istringstream(ios_base::openmode __mode, const allocator_type& __a)
+      : __istream_type(), _M_stringbuf(__mode | ios_base::in, __a)
+      { this->init(&_M_stringbuf); }
+
+      explicit basic_istringstream(__string_type&& __str,
+	                           ios_base::openmode __mode = ios_base::in )
+      : __istream_type(), _M_stringbuf(std::move(__str), __mode | ios_base::in)
+      { this->init(&_M_stringbuf); }
+
+      template<typename _SAlloc>
+	basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+			    const allocator_type& __a)
+	: basic_istringstream(__str, ios_base::in, __a)
+	{ }
+
+      using __sv_type = basic_string_view<char_type, traits_type>;
+
+      template<typename _SAlloc>
+	basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+			    ios_base::openmode __mode,
+			    const allocator_type& __a)
+	: __istream_type(),
+	_M_stringbuf(__string_type(__str.data(), __str.size()),
+		     __mode | ios_base::in, __a)
+	{ this->init(&_M_stringbuf); }
+
+      template<typename _SAlloc>
+	explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+	                             ios_base::openmode __mode = ios_base::in)
+	: basic_istringstream(__str, __mode, allocator_type())
+	{ }
+#endif
+
       // Members:
       /**
        *  @brief  Accessing the underlying buffer.
@@ -528,6 +640,12 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       void
       str(const __string_type& __s)
       { _M_stringbuf.str(__s); }
+
+#if __cplusplus > 201703L
+      __sv_type
+      view() const noexcept
+      { return _M_stringbuf.view(); }
+#endif
     };
 
 
@@ -658,6 +776,40 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       }
 #endif
 
+#if __cplusplus > 201703L
+      basic_ostringstream(ios_base::openmode __mode, const allocator_type& __a)
+      : __ostream_type(), _M_stringbuf(__mode | ios_base::out, __a)
+      { this->init(&_M_stringbuf); }
+
+      explicit basic_ostringstream(__string_type&& __str,
+	                           ios_base::openmode __mode = ios_base::out )
+      : __ostream_type(), _M_stringbuf(std::move(__str), __mode | ios_base::out)
+      { this->init(&_M_stringbuf); }
+
+      template<typename _SAlloc>
+	basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+			    const allocator_type& __a)
+	: basic_ostringstream(__str, ios_base::out, __a)
+	{ }
+
+      using __sv_type = basic_string_view<char_type, traits_type>;
+
+      template<typename _SAlloc>
+	basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+			    ios_base::openmode __mode,
+			    const allocator_type& __a)
+	: __ostream_type(),
+	_M_stringbuf(__string_type(__str.data(), __str.size()),
+		     __mode | ios_base::out, __a)
+	{ this->init(&_M_stringbuf); }
+
+      template<typename _SAlloc>
+	explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+	                             ios_base::openmode __mode = ios_base::out)
+	: basic_ostringstream(__str, __mode, allocator_type())
+	{ }
+#endif
+
       // Members:
       /**
        *  @brief  Accessing the underlying buffer.
@@ -686,6 +838,12 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       void
       str(const __string_type& __s)
       { _M_stringbuf.str(__s); }
+
+#if __cplusplus > 201703L
+      __sv_type
+      view() const noexcept
+      { return _M_stringbuf.view(); }
+#endif
     };
 
 
@@ -812,6 +970,40 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       }
 #endif
 
+#if __cplusplus > 201703L
+      basic_stringstream(ios_base::openmode __mode, const allocator_type& __a)
+      : __iostream_type(), _M_stringbuf(__mode, __a)
+      { this->init(&_M_stringbuf); }
+
+      explicit basic_stringstream(__string_type&& __str,
+	                          ios_base::openmode __mode = ios_base::out
+							      | ios_base::out)
+      : __iostream_type(), _M_stringbuf(std::move(__str), __mode)
+      { this->init(&_M_stringbuf); }
+
+      template<typename _SAlloc>
+	basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+			   const allocator_type& __a)
+	: basic_stringstream(__str, ios_base::in | ios_base::out, __a)
+	{ }
+
+      using __sv_type = basic_string_view<char_type, traits_type>;
+
+      template<typename _SAlloc>
+	basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+			   ios_base::openmode __mode, const allocator_type& __a)
+	: __iostream_type(),
+	_M_stringbuf(__string_type(__str.data(), __str.size()), __mode, __a)
+	{ this->init(&_M_stringbuf); }
+
+      template<typename _SAlloc>
+	explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
+	                            ios_base::openmode __mode = ios_base::in
+								| ios_base::out)
+	: basic_stringstream(__str, __mode, allocator_type())
+	{ }
+#endif
+
       // Members:
       /**
        *  @brief  Accessing the underlying buffer.
@@ -840,6 +1032,12 @@  _GLIBCXX_BEGIN_NAMESPACE_CXX11
       void
       str(const __string_type& __s)
       { _M_stringbuf.str(__s); }
+
+#if __cplusplus > 201703L
+      __sv_type
+      view() const noexcept
+      { return _M_stringbuf.view(); }
+#endif
     };
 
 #if __cplusplus >= 201103L
diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index a139adc81b3..9a6807ae8c6 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -29,7 +29,7 @@  filesystem_dir =
 endif
 
 ## Keep this list sync'd with acinclude.m4:GLIBCXX_CONFIGURE.
-SUBDIRS = c++98 c++11 c++17 $(filesystem_dir)
+SUBDIRS = c++98 c++11 c++17 c++20 $(filesystem_dir)
 
 # Cross compiler support.
 if VTV_CYGMIN
@@ -60,6 +60,7 @@  endif
 vpath % $(top_srcdir)/src/c++98
 vpath % $(top_srcdir)/src/c++11
 vpath % $(top_srcdir)/src/c++17
+vpath % $(top_srcdir)/src/c++20
 if ENABLE_FILESYSTEM_TS
 vpath % $(top_srcdir)/src/filesystem
 endif
@@ -95,14 +96,16 @@  libstdc___la_LIBADD = \
 	$(top_builddir)/libsupc++/libsupc++convenience.la \
 	$(top_builddir)/src/c++98/libc++98convenience.la \
 	$(top_builddir)/src/c++11/libc++11convenience.la \
-	$(top_builddir)/src/c++17/libc++17convenience.la
+	$(top_builddir)/src/c++17/libc++17convenience.la \
+	$(top_builddir)/src/c++20/libc++20convenience.la
 
 libstdc___la_DEPENDENCIES = \
 	${version_dep} \
 	$(top_builddir)/libsupc++/libsupc++convenience.la \
 	$(top_builddir)/src/c++98/libc++98convenience.la \
 	$(top_builddir)/src/c++11/libc++11convenience.la \
-	$(top_builddir)/src/c++17/libc++17convenience.la
+	$(top_builddir)/src/c++17/libc++17convenience.la \
+	$(top_builddir)/src/c++20/libc++20convenience.la
 
 libstdc___la_LDFLAGS = \
 	-version-info $(libtool_VERSION) ${version_arg} -lm
@@ -153,7 +156,8 @@  compatibility-condvar.o: compatibility-condvar.cc
 # segregated in the sources with -D_GLIBCXX_SHARED.
 #
 # In the sub-directories of libsupc++, src/c++98, src/c++11, src/c++17,
-# only -prefer-pic objects are generated for the convenience libraries.
+# src/c++20, only -prefer-pic objects are generated for the convenience
+# libraries.
 #
 # In the main src directory, make shared and static objects just for
 # the compat libraries. Shared objects are compiled with -prefer-pic
diff --git a/libstdc++-v3/src/c++20/Makefile.am b/libstdc++-v3/src/c++20/Makefile.am
new file mode 100644
index 00000000000..423a79f3686
--- /dev/null
+++ b/libstdc++-v3/src/c++20/Makefile.am
@@ -0,0 +1,105 @@ 
+## Makefile for the C++20 sources of the GNU C++ Standard library.
+##
+## Copyright (C) 1997-2020 Free Software Foundation, Inc.
+##
+## This file is part of the libstdc++ version 3 distribution.
+## Process this file with automake to produce Makefile.in.
+
+## This file is part of the GNU ISO C++ Library.  This library is free
+## software; you can redistribute it and/or modify it under the
+## terms of the GNU General Public License as published by the
+## Free Software Foundation; either version 3, or (at your option)
+## any later version.
+
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+
+## You should have received a copy of the GNU General Public License along
+## with this library; see the file COPYING3.  If not see
+## <http://www.gnu.org/licenses/>.
+
+include $(top_srcdir)/fragment.am
+
+# Convenience library for C++17 runtime.
+noinst_LTLIBRARIES = libc++20convenience.la
+
+headers =
+
+if ENABLE_EXTERN_TEMPLATE
+# XTEMPLATE_FLAGS = -fno-implicit-templates
+inst_sources = \
+	sstream-inst.cc
+else
+# XTEMPLATE_FLAGS =
+inst_sources =
+endif
+
+sources =
+
+vpath % $(top_srcdir)/src/c++20
+
+libc__20convenience_la_SOURCES = $(sources)  $(inst_sources)
+
+# AM_CXXFLAGS needs to be in each subdirectory so that it can be
+# modified in a per-library or per-sub-library way.  Need to manually
+# set this option because CONFIG_CXXFLAGS has to be after
+# OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
+# as the occasion calls for it.
+AM_CXXFLAGS = \
+	-std=gnu++20 \
+	$(glibcxx_lt_pic_flag) $(glibcxx_compiler_shared_flag) \
+	$(XTEMPLATE_FLAGS) $(VTV_CXXFLAGS) \
+	$(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) \
+	-fimplicit-templates
+
+AM_MAKEFLAGS = \
+	"gxx_include_dir=$(gxx_include_dir)"
+
+# Libtool notes
+
+# 1) In general, libtool expects an argument such as `--tag=CXX' when
+# using the C++ compiler, because that will enable the settings
+# detected when C++ support was being configured.  However, when no
+# such flag is given in the command line, libtool attempts to figure
+# it out by matching the compiler name in each configuration section
+# against a prefix of the command line.  The problem is that, if the
+# compiler name and its initial flags stored in the libtool
+# configuration file don't match those in the command line, libtool
+# can't decide which configuration to use, and it gives up.  The
+# correct solution is to add `--tag CXX' to LTCXXCOMPILE and maybe
+# CXXLINK, just after $(LIBTOOL), so that libtool doesn't have to
+# attempt to infer which configuration to use.
+#
+# The second tag argument, `--tag disable-shared` means that libtool
+# only compiles each source once, for static objects. In actuality,
+# glibcxx_lt_pic_flag and glibcxx_compiler_shared_flag are added to
+# the libtool command that is used create the object, which is
+# suitable for shared libraries.  The `--tag disable-shared` must be
+# placed after --tag CXX lest things CXX undo the affect of
+# disable-shared.
+
+# 2) Need to explicitly set LTCXXCOMPILE so that EXTRA_CXX_FLAGS is
+# last. (That way, things like -O2 passed down from the toplevel can
+# be overridden by --enable-debug.)
+LTCXXCOMPILE = \
+	$(LIBTOOL) --tag CXX --tag disable-shared \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CXX) $(TOPLEVEL_INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(EXTRA_CXX_FLAGS)
+
+LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
+
+# 3) We'd have a problem when building the shared libstdc++ object if
+# the rules automake generates would be used.  We cannot allow g++ to
+# be used since this would add -lstdc++ to the link line which of
+# course is problematic at this point.  So, we get the top-level
+# directory to configure libstdc++-v3 to use gcc as the C++
+# compilation driver.
+CXXLINK = \
+	$(LIBTOOL) --tag CXX --tag disable-shared \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CXX) \
+	$(VTV_CXXLINKFLAGS) \
+	$(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LTLDFLAGS) -o $@
diff --git a/libstdc++-v3/src/c++20/Makefile.in b/libstdc++-v3/src/c++20/Makefile.in
new file mode 100644
index 00000000000..0e2de19ae59
diff --git a/libstdc++-v3/src/c++20/sstream-inst.cc b/libstdc++-v3/src/c++20/sstream-inst.cc
new file mode 100644
index 00000000000..c7fa065bf18
--- /dev/null
+++ b/libstdc++-v3/src/c++20/sstream-inst.cc
@@ -0,0 +1,110 @@ 
+// Explicit instantiation file.
+
+// Copyright (C) 1997-2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+//
+// ISO C++ 14882:
+//
+
+#ifndef _GLIBCXX_USE_CXX11_ABI
+// Instantiations in this file use the new SSO std::string ABI unless included
+// by another file which defines _GLIBCXX_USE_CXX11_ABI=0.
+# define _GLIBCXX_USE_CXX11_ABI 1
+#endif
+#include <sstream>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+template basic_stringbuf<char>::basic_stringbuf(const allocator_type&);
+template basic_stringbuf<char>::basic_stringbuf(ios_base::openmode,
+                                                const allocator_type&);
+template basic_stringbuf<char>::basic_stringbuf(__string_type&&,
+                                                ios_base::openmode);
+template basic_stringbuf<char>::basic_stringbuf(basic_stringbuf&&,
+                                                const allocator_type&);
+template basic_stringbuf<char>::allocator_type
+                    basic_stringbuf<char>::get_allocator() const noexcept;
+template basic_stringbuf<char>::__sv_type 
+                    basic_stringbuf<char>::view() const noexcept;
+
+
+template basic_istringstream<char>::basic_istringstream(ios_base::openmode,
+                                                const allocator_type&);
+template basic_istringstream<char>::basic_istringstream(__string_type&&,
+                                                ios_base::openmode);
+template basic_istringstream<char>::__sv_type 
+                    basic_istringstream<char>::view() const noexcept;
+
+template basic_ostringstream<char>::basic_ostringstream(ios_base::openmode,
+                                                const allocator_type&);
+template basic_ostringstream<char>::basic_ostringstream(__string_type&&,
+                                                ios_base::openmode);
+template basic_ostringstream<char>::__sv_type 
+                    basic_ostringstream<char>::view() const noexcept;
+
+template basic_stringstream<char>::basic_stringstream(ios_base::openmode,
+                                                const allocator_type&);
+template basic_stringstream<char>::basic_stringstream(__string_type&&,
+                                                ios_base::openmode);
+template basic_stringstream<char>::__sv_type 
+                    basic_stringstream<char>::view() const noexcept;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+template basic_stringbuf<wchar_t>::basic_stringbuf(const allocator_type&);
+template basic_stringbuf<wchar_t>::basic_stringbuf(ios_base::openmode,
+                                                   const allocator_type&);
+template basic_stringbuf<wchar_t>::basic_stringbuf(__string_type&&,
+                                                   ios_base::openmode);
+template basic_stringbuf<wchar_t>::basic_stringbuf(basic_stringbuf&&,
+                                                   const allocator_type&);
+template basic_stringbuf<wchar_t>::allocator_type
+                    basic_stringbuf<wchar_t>::get_allocator() const noexcept;
+template basic_stringbuf<wchar_t>::__sv_type 
+                    basic_stringbuf<wchar_t>::view() const noexcept;
+
+template basic_istringstream<wchar_t>::basic_istringstream(ios_base::openmode,
+                                                const allocator_type&);
+template basic_istringstream<wchar_t>::basic_istringstream(__string_type&&,
+                                                ios_base::openmode);
+template basic_istringstream<wchar_t>::__sv_type 
+                    basic_istringstream<wchar_t>::view() const noexcept;
+
+template basic_ostringstream<wchar_t>::basic_ostringstream(ios_base::openmode,
+                                                const allocator_type&);
+template basic_ostringstream<wchar_t>::basic_ostringstream(__string_type&&,
+                                                ios_base::openmode);
+template basic_ostringstream<wchar_t>::__sv_type 
+                    basic_ostringstream<wchar_t>::view() const noexcept;
+
+template basic_stringstream<wchar_t>::basic_stringstream(ios_base::openmode,
+                                                const allocator_type&);
+template basic_stringstream<wchar_t>::basic_stringstream(__string_type&&,
+                                                ios_base::openmode);
+template basic_stringstream<wchar_t>::__sv_type 
+                    basic_stringstream<wchar_t>::view() const noexcept;
+#endif
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
new file mode 100644
index 00000000000..c902e55c4f7
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
@@ -0,0 +1,84 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::istringstream::allocator_type a;
+  std::istringstream stm(std::ios_base::in, a);
+}
+
+auto const cstr = "This is a test";
+
+void
+test02()
+{
+  std::string s1(cstr);
+  std::istringstream stm(std::move(s1));
+  VERIFY( s1.empty() );
+
+  std::string s2(cstr);
+  VERIFY( stm.str() == s2 );
+}
+
+void
+test03()
+{
+  using alloc_type = __gnu_test::tracker_allocator<char>;
+  using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
+
+  auto const mode = std::ios_base::in;
+  str_type s1(cstr);
+
+  {
+    std::istringstream::allocator_type a;
+    std::istringstream sbuf(s1, mode, a);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::istringstream sbuf(s1, mode);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::istringstream sbuf(s1);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc
new file mode 100644
index 00000000000..db1e3ff1728
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc
@@ -0,0 +1,84 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::wistringstream::allocator_type a;
+  std::wistringstream stm(std::ios_base::in, a);
+}
+
+auto const cstr = L"This is a test";
+
+void
+test02()
+{
+  std::wstring s1(cstr);
+  std::wistringstream stm(std::move(s1));
+  VERIFY( s1.empty() );
+
+  std::wstring s2(cstr);
+  VERIFY( stm.str() == s2 );
+}
+
+void
+test03()
+{
+  using alloc_type = __gnu_test::tracker_allocator<wchar_t>;
+  using str_type = std::basic_string<wchar_t, std::char_traits<wchar_t>, alloc_type>;
+
+  auto const mode = std::ios_base::in;
+  str_type s1(cstr);
+
+  {
+    std::wistringstream::allocator_type a;
+    std::wistringstream sbuf(s1, mode, a);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::wistringstream sbuf(s1, mode);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::wistringstream sbuf(s1);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/view/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/view/char/1.cc
new file mode 100644
index 00000000000..6859fec2ce9
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/view/char/1.cc
@@ -0,0 +1,34 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+  std::string s("This is a test");
+  std::istringstream stm(s);
+  VERIFY( stm.view() == s );
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/view/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/view/wchar_t/1.cc
new file mode 100644
index 00000000000..3c447bb23e9
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/view/wchar_t/1.cc
@@ -0,0 +1,35 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+  std::wstring s(L"This is a test");
+  std::wistringstream stm(s);
+  VERIFY( stm.view() == s );
+  return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc
new file mode 100644
index 00000000000..f7f71e0aa99
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc
@@ -0,0 +1,84 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::ostringstream::allocator_type a;
+  std::ostringstream stm(std::ios_base::in, a);
+}
+
+auto const cstr = "This is a test";
+
+void
+test02()
+{
+  std::string s1(cstr);
+  std::ostringstream stm(std::move(s1));
+  VERIFY( s1.empty() );
+
+  std::string s2(cstr);
+  VERIFY( stm.str() == s2 );
+}
+
+void
+test03()
+{
+  using alloc_type = __gnu_test::tracker_allocator<char>;
+  using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
+
+  auto const mode = std::ios_base::out;
+  str_type s1(cstr);
+
+  {
+    std::ostringstream::allocator_type a;
+    std::ostringstream sbuf(s1, mode, a);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::ostringstream sbuf(s1, mode);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::ostringstream sbuf(s1);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc
new file mode 100644
index 00000000000..10c28fe5880
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc
@@ -0,0 +1,84 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::wostringstream::allocator_type a;
+  std::wostringstream stm(std::ios_base::out, a);
+}
+
+auto const cstr = L"This is a test";
+
+void
+test02()
+{
+  std::wstring s1(cstr);
+  std::wostringstream stm(std::move(s1));
+  VERIFY( s1.empty() );
+
+  std::wstring s2(cstr);
+  VERIFY( stm.str() == s2 );
+}
+
+void
+test03()
+{
+  using alloc_type = __gnu_test::tracker_allocator<wchar_t>;
+  using str_type = std::basic_string<wchar_t, std::char_traits<wchar_t>, alloc_type>;
+
+  auto const mode = std::ios_base::out;
+  str_type s1(cstr);
+
+  {
+    std::wostringstream::allocator_type a;
+    std::wostringstream sbuf(s1, mode, a);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::wostringstream sbuf(s1, mode);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::wostringstream sbuf(s1);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/view/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/view/char/1.cc
new file mode 100644
index 00000000000..d080e3c7771
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/view/char/1.cc
@@ -0,0 +1,34 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+  std::string s("This is a test");
+  std::ostringstream stm(s);
+  VERIFY( stm.view() == s );
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc
new file mode 100644
index 00000000000..8cb51a30e24
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc
@@ -0,0 +1,35 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+  std::wstring s(L"This is a test");
+  std::wostringstream stm(s);
+  VERIFY( stm.view() == s );
+  return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc
new file mode 100644
index 00000000000..e611a2fcfce
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc
@@ -0,0 +1,120 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  {
+    using alloc_type = __gnu_test::uneq_allocator<char>;
+    using sbuf_t = std::basic_stringbuf<char, std::char_traits<char>,
+                                          alloc_type>;
+
+    alloc_type aa;
+    sbuf_t sbuf1(aa);
+    VERIFY( aa == sbuf1.get_allocator() );
+
+    alloc_type aaa(42);
+    sbuf_t sbuf2(aaa);
+    VERIFY( aaa == sbuf2.get_allocator() );
+
+    VERIFY( sbuf1.get_allocator() != sbuf2.get_allocator() );
+  }
+
+  std::stringbuf::allocator_type a;
+  {
+    std::stringbuf sbuf(std::ios_base::in, a);
+  }
+
+  {
+    std::stringbuf sbuf(a);
+  }
+}
+
+auto const cstr = "This is a test";
+
+void
+test02()
+{
+  std::string s1(cstr);
+  std::stringbuf sbuf(std::move(s1));
+  VERIFY( s1.empty() );
+
+  std::string s2(cstr);
+  VERIFY( sbuf.str() == s2 );
+}
+
+void
+test03()
+{
+  using alloc_type = __gnu_test::tracker_allocator<char>;
+  using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
+
+  auto const mode = std::ios_base::in | std::ios_base::out;
+  str_type s1(cstr);
+
+  {
+    std::stringbuf::allocator_type a;
+    std::stringbuf sbuf(s1, mode, a);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::stringbuf sbuf(s1, mode);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::stringbuf sbuf(s1);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+}
+
+void
+test04()
+{
+  std::stringbuf sbuf1(cstr);
+
+  std::stringbuf::allocator_type a;
+  std::stringbuf sbuf2(std::move(sbuf1), a);
+  VERIFY( sbuf1.str().empty() );
+
+  std::string s(cstr);
+  VERIFY( sbuf2.str() == s );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  test04();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc
new file mode 100644
index 00000000000..d2c435b2f10
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc
@@ -0,0 +1,105 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::wstringbuf::allocator_type a;
+  {
+    std::wstringbuf sbuf(std::ios_base::in, a);
+  }
+
+  {
+    std::wstringbuf sbuf(a);
+  }
+}
+
+auto const cstr = L"This is a test";
+
+void
+test02()
+{
+  std::wstring s1(cstr);
+  std::wstringbuf sbuf(std::move(s1));
+  VERIFY( s1.empty() );
+
+  std::wstring s2(cstr);
+  VERIFY( sbuf.str() == s2 );
+}
+
+void
+test03()
+{
+  using alloc_type = __gnu_test::tracker_allocator<wchar_t>;
+  using str_type = std::basic_string<wchar_t, std::char_traits<wchar_t>, alloc_type>;
+
+  auto const mode = std::ios_base::in | std::ios_base::out;
+  str_type s1(cstr);
+
+  {
+    std::wstringbuf::allocator_type a;
+    std::wstringbuf sbuf(s1, mode, a);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::wstringbuf sbuf(s1, mode);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::wstringbuf sbuf(s1);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+}
+
+void
+test04()
+{
+  std::wstringbuf sbuf1(cstr);
+
+  std::wstringbuf::allocator_type a;
+  std::wstringbuf sbuf2(std::move(sbuf1), a);
+  VERIFY( sbuf1.str().empty() );
+
+  std::wstring s(cstr);
+  VERIFY( sbuf2.str() == s );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  test04();
+  return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/view/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/view/char/1.cc
new file mode 100644
index 00000000000..40af4b094cb
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/view/char/1.cc
@@ -0,0 +1,34 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+  std::string s("This is a test");
+  std::stringbuf sbuf(s);
+  VERIFY( sbuf.view() == s );
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc
new file mode 100644
index 00000000000..ffa27996803
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc
@@ -0,0 +1,35 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+  std::wstring s(L"This is a test");
+  std::wstringbuf sbuf(s);
+  VERIFY( sbuf.view() == s );
+  return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc
new file mode 100644
index 00000000000..021341342be
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc
@@ -0,0 +1,84 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::stringstream::allocator_type a;
+  std::stringstream stm(std::ios_base::in, a);
+}
+
+auto const cstr = "This is a test";
+
+void
+test02()
+{
+  std::string s1(cstr);
+  std::stringstream stm(std::move(s1));
+  VERIFY( s1.empty() );
+
+  std::string s2(cstr);
+  VERIFY( stm.str() == s2 );
+}
+
+void
+test03()
+{
+  using alloc_type = __gnu_test::tracker_allocator<char>;
+  using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
+
+  auto const mode = std::ios_base::in | std::ios_base::out;
+  str_type s1(cstr);
+
+  {
+    std::stringstream::allocator_type a;
+    std::stringstream sbuf(s1, mode, a);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::stringstream sbuf(s1, mode);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::stringstream sbuf(s1);
+    std::string s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc
new file mode 100644
index 00000000000..db1e3ff1728
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc
@@ -0,0 +1,84 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::wistringstream::allocator_type a;
+  std::wistringstream stm(std::ios_base::in, a);
+}
+
+auto const cstr = L"This is a test";
+
+void
+test02()
+{
+  std::wstring s1(cstr);
+  std::wistringstream stm(std::move(s1));
+  VERIFY( s1.empty() );
+
+  std::wstring s2(cstr);
+  VERIFY( stm.str() == s2 );
+}
+
+void
+test03()
+{
+  using alloc_type = __gnu_test::tracker_allocator<wchar_t>;
+  using str_type = std::basic_string<wchar_t, std::char_traits<wchar_t>, alloc_type>;
+
+  auto const mode = std::ios_base::in;
+  str_type s1(cstr);
+
+  {
+    std::wistringstream::allocator_type a;
+    std::wistringstream sbuf(s1, mode, a);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::wistringstream sbuf(s1, mode);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+
+  {
+    std::wistringstream sbuf(s1);
+    std::wstring s2(cstr);
+    VERIFY( sbuf.str() == s2 );
+  }
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  test03();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/view/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/view/char/1.cc
new file mode 100644
index 00000000000..c596b5872ed
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/view/char/1.cc
@@ -0,0 +1,34 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+  std::string s("This is a test");
+  std::stringstream stm(s);
+  VERIFY( stm.view() == s );
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/view/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/view/wchar_t/1.cc
new file mode 100644
index 00000000000..a5f251969c3
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/view/wchar_t/1.cc
@@ -0,0 +1,35 @@ 
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.1  basic_stringbuf constructors  [lib.stringbuf.cons]
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+  std::wstring s(L"This is a test");
+  std::wstringstream stm(s);
+  VERIFY( stm.view() == s );
+  return 0;
+}
+