diff options
author | Thomas Rodgers <trodgers@redhat.com> | 2020-10-28 11:52:17 -0700 |
---|---|---|
committer | Thomas Rodgers <trodgers@redhat.com> | 2020-10-28 11:56:06 -0700 |
commit | a0e4d7b44c544c84cffc7ff9c64b6f1af14fb08d (patch) | |
tree | 5436f8e6b2790a3d2c3c1c9a2ba7f50fe20c98d5 /libstdc++-v3/testsuite/27_io/basic_stringbuf/cons | |
parent | 4289e488dddc1f07a04feca6568b329f65b8fa10 (diff) | |
download | gcc-a0e4d7b44c544c84cffc7ff9c64b6f1af14fb08d.tar.gz |
libstdc++: Implement C++20 features for <sstream>
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 (GLIBCXX_3.4.29): New symbols.
* 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/1.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc: Likewise.
* testsuite/27_io/basic_istringstream/cons/char/1.cc: Likewise.
* testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc: Likewise.
* testsuite/27_io/basic_istringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_istringstream/view/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_ostringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/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.
* testsuite/27_io/basic_stringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/wchar_t/1.cc: Likewise.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_stringbuf/cons')
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc | 121 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc | 105 |
2 files changed, 226 insertions, 0 deletions
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..ce669358c85 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/2.cc @@ -0,0 +1,121 @@ +// 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 } } +// { dg-require-effective-target cxx11-abi } + +#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..e05acc42165 --- /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 } } +// { dg-require-effective-target cxx11-abi } + +#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; +} |