1 // Copyright (C) 2018 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 // { dg-options "-Wno-deprecated" }
19 // { dg-do run { target c++11 } }
22 #include <testsuite_hooks.h>
27 std::istrstream
is("15 16");
28 std::istrstream is2
= std::move(is
);
35 std::istrstream is3
= std::move(is2
);
47 std::istrstream
is("");
51 is
= std::istrstream("17 18");
55 is
= std::istrstream("");
65 os
<< "a few chars"; // fits in initial allocation
66 char* s
= os
.str(); // os now frozen
67 std::ostrstream os2
= std::move(os
);
68 VERIFY( os2
.str() == s
);
69 VERIFY( os
.str() == nullptr );
72 os2
<< "enough additional chars to force a reallocation";
74 s
= os2
.str(); // os2 now frozen
75 std::ostrstream os3
= std::move(os2
);
76 VERIFY( os3
.str() == s
);
77 VERIFY( os2
.str() == nullptr );
85 std::ostrstream
os(buf
, sizeof(buf
));
87 char* s
= os
.str(); // os now frozen
89 std::ostrstream os2
= std::move(os
);
90 VERIFY( os2
.str() == s
);
91 VERIFY( os
.str() == nullptr );
94 os2
<< "enough additional chars to force a reallocation";
96 s
= os2
.str(); // os2 now frozen
98 std::ostrstream os3
= std::move(os2
);
99 VERIFY( os3
.str() == s
);
100 VERIFY( os2
.str() == nullptr );
106 char buf
[] = "0123456789";
107 std::ostrstream
os(buf
, 1);
110 os
= std::ostrstream(buf
, 10);
113 VERIFY( os
.pcount() == 10 );
116 os
= std::ostrstream();
119 VERIFY( os
.pcount() == 1 );
120 char* s
= os
.str(); // os now frozen
121 os
= std::ostrstream();
122 os
.freeze(false); // no effect
129 char buf
[] = "15 16";
130 std::strstream
ss(buf
, 5, std::ios::in
|std::ios::app
);
131 std::strstream ss2
= std::move(ss
);
138 std::strstream ss3
= std::move(ss2
);
154 char buf
[] = "17 18";
155 ss
= std::strstream(buf
, 5, std::ios::in
|std::ios::app
);
159 ss
= std::strstream();
169 ss
<< "a few chars"; // fits in initial allocation
170 char* s
= ss
.str(); // ss now frozen
171 std::strstream ss2
= std::move(ss
);
172 VERIFY( ss2
.str() == s
);
173 VERIFY( ss
.str() == nullptr );
176 ss2
<< "enough additional chars to force a reallocation";
178 s
= ss2
.str(); // ss2 now frozen
179 std::strstream ss3
= std::move(ss2
);
180 VERIFY( ss3
.str() == s
);
181 VERIFY( ss2
.str() == nullptr );
189 std::strstream
ss(buf
, sizeof(buf
));
191 char* s
= ss
.str(); // ss now frozen
193 std::strstream ss2
= std::move(ss
);
194 VERIFY( ss2
.str() == s
);
195 VERIFY( ss
.str() == nullptr );
198 ss2
<< "enough additional chars to force a reallocation";
200 s
= ss2
.str(); // ss2 now frozen
202 std::strstream ss3
= std::move(ss2
);
203 VERIFY( ss3
.str() == s
);
204 VERIFY( ss2
.str() == nullptr );
210 char buf
[] = "0123456789";
211 std::strstream
ss(buf
, 1);
214 ss
= std::strstream(buf
, 10);
217 VERIFY( ss
.pcount() == 10 );
220 ss
= std::strstream();
223 VERIFY( ss
.pcount() == 1 );
224 char* s
= ss
.str(); // ss now frozen
225 ss
= std::strstream();
226 ss
.freeze(false); // no effect