1 // Copyright (C) 2020 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // C++20 29.8.2.2 basic_stringbuf constructors [stringbuf.cons
20 // { dg-options "-std=gnu++2a" }
21 // { dg-do run { target c++2a } }
22 // { dg-require-effective-target cxx11-abi }
26 #include <testsuite_allocator.h>
27 #include <testsuite_hooks.h>
32 std::ostringstream::allocator_type a
;
33 std::ostringstream
stm(std::ios_base::in
, a
);
36 auto const cstr
= "This is a test string";
42 std::ostringstream
stm(std::move(s1
));
46 VERIFY( stm
.str() == s2
);
52 using alloc_type
= __gnu_test::tracker_allocator
<char>;
53 using str_type
= std::basic_string
<char, std::char_traits
<char>, alloc_type
>;
55 auto const mode
= std::ios_base::out
;
59 std::ostringstream::allocator_type a
;
60 std::ostringstream
sbuf(s1
, mode
, a
);
62 VERIFY( sbuf
.str() == s2
);
66 std::ostringstream
sbuf(s1
, mode
);
68 VERIFY( sbuf
.str() == s2
);
72 std::ostringstream
sbuf(s1
);
74 VERIFY( sbuf
.str() == s2
);
78 // A minimal allocator with no default constructor
80 struct NoDefaultCons
: __gnu_test::SimpleAllocator
<T
>
82 using __gnu_test::SimpleAllocator
<T
>::SimpleAllocator
;
84 NoDefaultCons() = delete;
86 NoDefaultCons(int) { }
92 using sstream
= std::basic_ostringstream
<char, std::char_traits
<char>,
95 NoDefaultCons
<char> a(1);
96 const std::string
str(cstr
);
99 VERIFY( ss1
.str() == cstr
);
101 sstream
ss2(str
, std::ios::in
, a
);
102 VERIFY( ss2
.str() == cstr
);
103 VERIFY( bool(ss2
<< "That") );
104 VERIFY( ss2
.str() == "That is a test string" );
106 sstream
ss3(std::string(str
), std::ios::ate
, a
);
107 VERIFY( ss3
.str() == cstr
);
108 VERIFY( bool(ss3
<< "y thing") );
109 VERIFY( ss3
.str() == "This is a test stringy thing" );