Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / output.streams / ostream.assign / move_assign.pass.cpp
blobdbac8387b88af284649e2e5ee1204e97859371dd
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <ostream>
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_ostream;
14 // basic_ostream& operator=(basic_ostream&& rhs);
16 #include <ostream>
17 #include <cassert>
19 #include "test_macros.h"
22 template <class CharT>
23 struct testbuf
24 : public std::basic_streambuf<CharT>
26 testbuf() {}
29 template <class CharT>
30 struct test_ostream
31 : public std::basic_ostream<CharT>
33 typedef std::basic_ostream<CharT> base;
34 test_ostream(testbuf<CharT>* sb) : base(sb) {}
36 test_ostream& operator=(test_ostream&& s)
37 {base::operator=(std::move(s)); return *this;}
41 int main(int, char**)
44 testbuf<char> sb1;
45 testbuf<char> sb2;
46 test_ostream<char> os1(&sb1);
47 test_ostream<char> os2(&sb2);
48 os2 = (std::move(os1));
49 assert(os1.rdbuf() == &sb1);
50 assert(os1.tie() == 0);
51 assert(os1.fill() == ' ');
52 assert(os1.rdstate() == os1.goodbit);
53 assert(os1.exceptions() == os1.goodbit);
54 assert(os1.flags() == (os1.skipws | os1.dec));
55 assert(os1.precision() == 6);
56 assert(os1.getloc().name() == "C");
57 assert(os2.rdbuf() == &sb2);
58 assert(os2.tie() == 0);
59 assert(os2.fill() == ' ');
60 assert(os2.rdstate() == os2.goodbit);
61 assert(os2.exceptions() == os2.goodbit);
62 assert(os2.flags() == (os2.skipws | os2.dec));
63 assert(os2.precision() == 6);
64 assert(os2.getloc().name() == "C");
66 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
68 testbuf<wchar_t> sb1;
69 testbuf<wchar_t> sb2;
70 test_ostream<wchar_t> os1(&sb1);
71 test_ostream<wchar_t> os2(&sb2);
72 os2 = (std::move(os1));
73 assert(os1.rdbuf() == &sb1);
74 assert(os1.tie() == 0);
75 assert(os1.fill() == ' ');
76 assert(os1.rdstate() == os1.goodbit);
77 assert(os1.exceptions() == os1.goodbit);
78 assert(os1.flags() == (os1.skipws | os1.dec));
79 assert(os1.precision() == 6);
80 assert(os1.getloc().name() == "C");
81 assert(os2.rdbuf() == &sb2);
82 assert(os2.tie() == 0);
83 assert(os2.fill() == ' ');
84 assert(os2.rdstate() == os2.goodbit);
85 assert(os2.exceptions() == os2.goodbit);
86 assert(os2.flags() == (os2.skipws | os2.dec));
87 assert(os2.precision() == 6);
88 assert(os2.getloc().name() == "C");
90 #endif
92 return 0;