public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Improve tests for stringstream constructors in C++20
Date: Fri, 19 Nov 2021 20:25:09 +0000	[thread overview]
Message-ID: <20211119202509.502181-1-jwakely@redhat.com> (raw)

Tested x86_64-linux, pushed to trunk.


This ensures all constructors are checked.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_istringstream/cons/char/1.cc: Check all
	constructors.
	* testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_ostringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_stringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc:
	Likewise.
---
 .../27_io/basic_istringstream/cons/char/1.cc  | 119 +++++++++++++++--
 .../basic_istringstream/cons/wchar_t/1.cc     | 119 +++++++++++++++--
 .../27_io/basic_ostringstream/cons/char/1.cc  | 121 ++++++++++++++---
 .../basic_ostringstream/cons/wchar_t/1.cc     | 122 +++++++++++++++---
 .../27_io/basic_stringstream/cons/char/1.cc   | 121 ++++++++++++++---
 .../basic_stringstream/cons/wchar_t/1.cc      | 119 +++++++++++++++--
 6 files changed, 633 insertions(+), 88 deletions(-)

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 bfd56b98dff..a3c736eba0c 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
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// C++20 29.8.2.2  basic_stringbuf constructors  [stringbuf.cons
+// C++20 29.8.3.2  basic_istringstream constructors  [istringstream.cons]
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
@@ -49,29 +49,120 @@ test02()
 void
 test03()
 {
-  using alloc_type = __gnu_test::tracker_allocator<char>;
-  using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
+  using C = char;
+  using alloc_type = __gnu_test::uneq_allocator<C>;
+  using traits_type = std::char_traits<C>;
+  using string = std::basic_string<C, traits_type, alloc_type>;
+  using istringstream = std::basic_istringstream<C, traits_type, alloc_type>;
 
   auto const mode = std::ios_base::in;
-  str_type s1(cstr);
+  alloc_type a1(1);
+  const string s1(cstr, a1);
 
+  // basic_istringstream()
   {
-    std::istringstream::allocator_type a;
-    std::istringstream sbuf(s1, mode, a);
-    std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    istringstream ss;
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_istringstream(openmode)
   {
-    std::istringstream sbuf(s1, mode);
-    std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    istringstream ss(mode);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_istringstream(const basic_string<C,T,A>&, openmode = in)
   {
-    std::istringstream sbuf(s1);
-    std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    istringstream ss(s1);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,A>&, openmode = in)
+  {
+    istringstream ss(s1, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(openmode, const A&)
+  {
+    istringstream ss(mode, a1);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    istringstream ss(string{s1});
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    istringstream ss(string(s1), mode);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    istringstream ss(s1, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    const std::string s2 = cstr;
+    istringstream ss(s2, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    istringstream ss(s1, mode, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    const std::string s2 = cstr;
+    istringstream ss(s2, mode, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, openmode = in)
+  {
+    alloc_type a0;
+    const std::string s2 = cstr;
+    istringstream ss(s2, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 }
 
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
index 5573a72311d..a3c1afe6aa2 100644
--- 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
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// C++20 29.8.2.2  basic_stringbuf constructors  [stringbuf.cons
+// C++20 29.8.3.2  basic_istringstream constructors  [istringstream.cons]
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
@@ -49,29 +49,120 @@ test02()
 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>;
+  using C = wchar_t;
+  using alloc_type = __gnu_test::uneq_allocator<C>;
+  using traits_type = std::char_traits<C>;
+  using string = std::basic_string<C, traits_type, alloc_type>;
+  using istringstream = std::basic_istringstream<C, traits_type, alloc_type>;
 
   auto const mode = std::ios_base::in;
-  str_type s1(cstr);
+  alloc_type a1(1);
+  const string s1(cstr, a1);
 
+  // basic_istringstream()
   {
-    std::wistringstream::allocator_type a;
-    std::wistringstream sbuf(s1, mode, a);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    istringstream ss;
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_istringstream(openmode)
   {
-    std::wistringstream sbuf(s1, mode);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    istringstream ss(mode);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_istringstream(const basic_string<C,T,A>&, openmode = in)
   {
-    std::wistringstream sbuf(s1);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    istringstream ss(s1);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,A>&, openmode = in)
+  {
+    istringstream ss(s1, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(openmode, const A&)
+  {
+    istringstream ss(mode, a1);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    istringstream ss(string{s1});
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    istringstream ss(string(s1), mode);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    istringstream ss(s1, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    const std::wstring s2 = cstr;
+    istringstream ss(s2, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    istringstream ss(s1, mode, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    const std::wstring s2 = cstr;
+    istringstream ss(s2, mode, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_istringstream(const basic_string<C,T,SA>&, openmode = in)
+  {
+    alloc_type a0;
+    const std::wstring s2 = cstr;
+    istringstream ss(s2, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 }
 
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 93d35756a74..a337916441e 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
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// C++20 29.8.2.2  basic_stringbuf constructors  [stringbuf.cons
+// C++20 29.8.4.2  basic_ostringstream constructors  [ostringstream.cons]
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
@@ -49,29 +49,120 @@ test02()
 void
 test03()
 {
-  using alloc_type = __gnu_test::tracker_allocator<char>;
-  using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
+  using C = char;
+  using alloc_type = __gnu_test::uneq_allocator<C>;
+  using traits_type = std::char_traits<C>;
+  using string = std::basic_string<C, traits_type, alloc_type>;
+  using ostringstream = std::basic_ostringstream<C, traits_type, alloc_type>;
 
-  auto const mode = std::ios_base::out;
-  str_type s1(cstr);
+  auto const mode = std::ios_base::in;
+  alloc_type a1(1);
+  const string s1(cstr, a1);
 
+  // basic_ostringstream()
   {
-    std::ostringstream::allocator_type a;
-    std::ostringstream sbuf(s1, mode, a);
-    std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    ostringstream ss;
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_ostringstream(openmode)
   {
-    std::ostringstream sbuf(s1, mode);
-    std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    ostringstream ss(mode);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_ostringstream(const basic_string<C,T,A>&, openmode = in)
   {
-    std::ostringstream sbuf(s1);
-    std::string s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    ostringstream ss(s1);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,A>&, openmode = in)
+  {
+    ostringstream ss(s1, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(openmode, const A&)
+  {
+    ostringstream ss(mode, a1);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    ostringstream ss(string{s1});
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    ostringstream ss(string(s1), mode);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    ostringstream ss(s1, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    const std::string s2 = cstr;
+    ostringstream ss(s2, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    ostringstream ss(s1, mode, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    const std::string s2 = cstr;
+    ostringstream ss(s2, mode, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, openmode = in)
+  {
+    alloc_type a0;
+    const std::string s2 = cstr;
+    ostringstream ss(s2, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 }
 
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
index 12767c781d7..12e40a79740 100644
--- 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
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// C++20 29.8.2.2  basic_stringbuf constructors  [stringbuf.cons
+// C++20 29.8.4.2  basic_ostringstream constructors  [ostringstream.cons]
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
@@ -49,32 +49,122 @@ test02()
 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>;
+  using C = wchar_t;
+  using alloc_type = __gnu_test::uneq_allocator<C>;
+  using traits_type = std::char_traits<C>;
+  using string = std::basic_string<C, traits_type, alloc_type>;
+  using ostringstream = std::basic_ostringstream<C, traits_type, alloc_type>;
 
-  auto const mode = std::ios_base::out;
-  str_type s1(cstr);
+  auto const mode = std::ios_base::in;
+  alloc_type a1(1);
+  const string s1(cstr, a1);
 
+  // basic_ostringstream()
   {
-    std::wostringstream::allocator_type a;
-    std::wostringstream sbuf(s1, mode, a);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    ostringstream ss;
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_ostringstream(openmode)
   {
-    std::wostringstream sbuf(s1, mode);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    ostringstream ss(mode);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_ostringstream(const basic_string<C,T,A>&, openmode = in)
   {
-    std::wostringstream sbuf(s1);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    ostringstream ss(s1);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,A>&, openmode = in)
+  {
+    ostringstream ss(s1, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(openmode, const A&)
+  {
+    ostringstream ss(mode, a1);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    ostringstream ss(string{s1});
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    ostringstream ss(string(s1), mode);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    ostringstream ss(s1, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    const std::wstring s2 = cstr;
+    ostringstream ss(s2, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    ostringstream ss(s1, mode, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    const std::wstring s2 = cstr;
+    ostringstream ss(s2, mode, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_ostringstream(const basic_string<C,T,SA>&, openmode = in)
+  {
+    alloc_type a0;
+    const std::wstring s2 = cstr;
+    ostringstream ss(s2, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 }
-
 int
 main()
 {
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 7cb9f34ca04..6395ae3e242 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
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// C++20 29.8.2.2  basic_stringbuf constructors  [stringbuf.cons
+// C++20 29.8.5.2  basic_stringstream constructors  [stringstream.cons]
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
@@ -49,29 +49,120 @@ test02()
 void
 test03()
 {
-  using alloc_type = __gnu_test::tracker_allocator<char>;
-  using str_type = std::basic_string<char, std::char_traits<char>, alloc_type>;
+  using C = char;
+  using alloc_type = __gnu_test::uneq_allocator<C>;
+  using traits_type = std::char_traits<C>;
+  using string = std::basic_string<C, traits_type, alloc_type>;
+  using stringstream = std::basic_stringstream<C, traits_type, alloc_type>;
 
-  auto const mode = std::ios_base::in | std::ios_base::out;
-  str_type s1(cstr);
+  auto const mode = std::ios_base::in;
+  alloc_type a1(1);
+  const string s1(cstr, a1);
 
+  // basic_stringstream()
   {
-    std::stringstream::allocator_type a;
-    std::stringstream ss(s1, mode, a);
-    std::string s2(cstr);
-    VERIFY( ss.str() == s2 );
+    alloc_type a0;
+    stringstream ss;
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_stringstream(openmode)
   {
-    std::stringstream ss(s1, mode);
-    std::string s2(cstr);
-    VERIFY( ss.str() == s2 );
+    alloc_type a0;
+    stringstream ss(mode);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_stringstream(const basic_string<C,T,A>&, openmode = in)
   {
-    std::stringstream ss(s1);
-    std::string s2(cstr);
-    VERIFY( ss.str() == s2 );
+    stringstream ss(s1);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,A>&, openmode = in)
+  {
+    stringstream ss(s1, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(openmode, const A&)
+  {
+    stringstream ss(mode, a1);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    stringstream ss(string{s1});
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    stringstream ss(string(s1), mode);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    stringstream ss(s1, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    const std::string s2 = cstr;
+    stringstream ss(s2, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    stringstream ss(s1, mode, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    const std::string s2 = cstr;
+    stringstream ss(s2, mode, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, openmode = in)
+  {
+    alloc_type a0;
+    const std::string s2 = cstr;
+    stringstream ss(s2, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 }
 
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
index 5573a72311d..d4c412276cc 100644
--- 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
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// C++20 29.8.2.2  basic_stringbuf constructors  [stringbuf.cons
+// C++20 29.8.5.2  basic_stringstream constructors  [stringstream.cons]
 
 // { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
@@ -49,29 +49,120 @@ test02()
 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>;
+  using C = wchar_t;
+  using alloc_type = __gnu_test::uneq_allocator<C>;
+  using traits_type = std::char_traits<C>;
+  using string = std::basic_string<C, traits_type, alloc_type>;
+  using stringstream = std::basic_stringstream<C, traits_type, alloc_type>;
 
   auto const mode = std::ios_base::in;
-  str_type s1(cstr);
+  alloc_type a1(1);
+  const string s1(cstr, a1);
 
+  // basic_stringstream()
   {
-    std::wistringstream::allocator_type a;
-    std::wistringstream sbuf(s1, mode, a);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    stringstream ss;
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_stringstream(openmode)
   {
-    std::wistringstream sbuf(s1, mode);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    alloc_type a0;
+    stringstream ss(mode);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 
+  // basic_stringstream(const basic_string<C,T,A>&, openmode = in)
   {
-    std::wistringstream sbuf(s1);
-    std::wstring s2(cstr);
-    VERIFY( sbuf.str() == s2 );
+    stringstream ss(s1);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,A>&, openmode = in)
+  {
+    stringstream ss(s1, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(openmode, const A&)
+  {
+    stringstream ss(mode, a1);
+    VERIFY( ss.str().empty() );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    stringstream ss(string{s1});
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(basic_string<C,T,A>&&, openmode = in)
+  {
+    stringstream ss(string(s1), mode);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a1 );
+    VERIFY( ss.str().get_allocator() == a1 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    stringstream ss(s1, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, const A&)
+  {
+    alloc_type a2(2);
+    const std::wstring s2 = cstr;
+    stringstream ss(s2, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    stringstream ss(s1, mode, a2);
+    VERIFY( ss.str() == s1 );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&)
+  {
+    alloc_type a2(2);
+    const std::wstring s2 = cstr;
+    stringstream ss(s2, mode, a2);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a2 );
+    VERIFY( ss.str().get_allocator() == a2 );
+  }
+
+  // basic_stringstream(const basic_string<C,T,SA>&, openmode = in)
+  {
+    alloc_type a0;
+    const std::wstring s2 = cstr;
+    stringstream ss(s2, mode);
+    VERIFY( ss.str() == cstr );
+    VERIFY( ss.rdbuf()->get_allocator() == a0 );
+    VERIFY( ss.str().get_allocator() == a0 );
   }
 }
 
-- 
2.31.1


                 reply	other threads:[~2021-11-19 20:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211119202509.502181-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).