Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / std.manip / setbase.pass.cpp
blob0e8b13c21bce0d451d14a01a748d32615e82c893
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 // <iomanip>
11 // T3 setbase(int base);
13 #include <iomanip>
14 #include <istream>
15 #include <ostream>
16 #include <cassert>
18 #include "test_macros.h"
20 template <class CharT>
21 struct testbuf
22 : public std::basic_streambuf<CharT>
24 testbuf() {}
27 int main(int, char**)
30 testbuf<char> sb;
31 std::istream is(&sb);
32 is >> std::setbase(8);
33 assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct);
34 is >> std::setbase(10);
35 assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec);
36 is >> std::setbase(16);
37 assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex);
38 is >> std::setbase(15);
39 assert((is.flags() & std::ios_base::basefield) == 0);
42 testbuf<char> sb;
43 std::ostream os(&sb);
44 os << std::setbase(8);
45 assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct);
46 os << std::setbase(10);
47 assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec);
48 os << std::setbase(16);
49 assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex);
50 os << std::setbase(15);
51 assert((os.flags() & std::ios_base::basefield) == 0);
53 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
55 testbuf<wchar_t> sb;
56 std::wistream is(&sb);
57 is >> std::setbase(8);
58 assert((is.flags() & std::ios_base::basefield) == std::ios_base::oct);
59 is >> std::setbase(10);
60 assert((is.flags() & std::ios_base::basefield) == std::ios_base::dec);
61 is >> std::setbase(16);
62 assert((is.flags() & std::ios_base::basefield) == std::ios_base::hex);
63 is >> std::setbase(15);
64 assert((is.flags() & std::ios_base::basefield) == 0);
67 testbuf<wchar_t> sb;
68 std::wostream os(&sb);
69 os << std::setbase(8);
70 assert((os.flags() & std::ios_base::basefield) == std::ios_base::oct);
71 os << std::setbase(10);
72 assert((os.flags() & std::ios_base::basefield) == std::ios_base::dec);
73 os << std::setbase(16);
74 assert((os.flags() & std::ios_base::basefield) == std::ios_base::hex);
75 os << std::setbase(15);
76 assert((os.flags() & std::ios_base::basefield) == 0);
78 #endif // TEST_HAS_NO_WIDE_CHARACTERS
80 return 0;