* [committed] libstdc++: Improve tests for stringstream constructors in C++20
@ 2021-11-19 20:25 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-11-19 20:25 UTC (permalink / raw)
To: libstdc++, gcc-patches
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-19 20:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19 20:25 [committed] libstdc++: Improve tests for stringstream constructors in C++20 Jonathan Wakely
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).