Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / input.streams / istream / istream.assign / move_assign.pass.cpp
blobfd79726d6b394a8a08d33ff89d906b20e788aa86
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 // <istream>
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_istream;
14 // basic_istream& operator=(basic_istream&& rhs);
16 #include <istream>
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_istream
31 : public std::basic_istream<CharT>
33 typedef std::basic_istream<CharT> base;
34 test_istream(testbuf<CharT>* sb) : base(sb) {}
36 test_istream& operator=(test_istream&& s)
37 {base::operator=(std::move(s)); return *this;}
41 int main(int, char**)
44 testbuf<char> sb1;
45 testbuf<char> sb2;
46 test_istream<char> is1(&sb1);
47 test_istream<char> is2(&sb2);
48 is2 = (std::move(is1));
49 assert(is1.rdbuf() == &sb1);
50 assert(is1.tie() == 0);
51 assert(is1.fill() == ' ');
52 assert(is1.rdstate() == is1.goodbit);
53 assert(is1.exceptions() == is1.goodbit);
54 assert(is1.flags() == (is1.skipws | is1.dec));
55 assert(is1.precision() == 6);
56 assert(is1.getloc().name() == "C");
57 assert(is2.rdbuf() == &sb2);
58 assert(is2.tie() == 0);
59 assert(is2.fill() == ' ');
60 assert(is2.rdstate() == is2.goodbit);
61 assert(is2.exceptions() == is2.goodbit);
62 assert(is2.flags() == (is2.skipws | is2.dec));
63 assert(is2.precision() == 6);
64 assert(is2.getloc().name() == "C");
66 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
68 testbuf<wchar_t> sb1;
69 testbuf<wchar_t> sb2;
70 test_istream<wchar_t> is1(&sb1);
71 test_istream<wchar_t> is2(&sb2);
72 is2 = (std::move(is1));
73 assert(is1.rdbuf() == &sb1);
74 assert(is1.tie() == 0);
75 assert(is1.fill() == ' ');
76 assert(is1.rdstate() == is1.goodbit);
77 assert(is1.exceptions() == is1.goodbit);
78 assert(is1.flags() == (is1.skipws | is1.dec));
79 assert(is1.precision() == 6);
80 assert(is1.getloc().name() == "C");
81 assert(is2.rdbuf() == &sb2);
82 assert(is2.tie() == 0);
83 assert(is2.fill() == ' ');
84 assert(is2.rdstate() == is2.goodbit);
85 assert(is2.exceptions() == is2.goodbit);
86 assert(is2.flags() == (is2.skipws | is2.dec));
87 assert(is2.precision() == 6);
88 assert(is2.getloc().name() == "C");
90 #endif
92 return 0;