Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostreams.base / ios / iostate.flags / setstate.pass.cpp
blobea954bee05e906fbcfa8dba0139cecd148f534f0
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 // <ios>
11 // template <class charT, class traits> class basic_ios
13 // void setstate(iostate state);
15 #include <ios>
16 #include <streambuf>
17 #include <cassert>
19 #include "test_macros.h"
21 struct testbuf : public std::streambuf {};
23 int main(int, char**)
26 std::ios ios(0);
27 ios.setstate(std::ios::goodbit);
28 assert(ios.rdstate() == std::ios::badbit);
29 #ifndef TEST_HAS_NO_EXCEPTIONS
30 try
32 ios.exceptions(std::ios::badbit);
33 assert(false);
35 catch (...)
38 try
40 ios.setstate(std::ios::goodbit);
41 assert(false);
43 catch (std::ios::failure&)
45 assert(ios.rdstate() == std::ios::badbit);
47 try
49 ios.setstate(std::ios::eofbit);
50 assert(false);
52 catch (std::ios::failure&)
54 assert(ios.rdstate() == (std::ios::eofbit | std::ios::badbit));
56 #endif
59 testbuf sb;
60 std::ios ios(&sb);
61 ios.setstate(std::ios::goodbit);
62 assert(ios.rdstate() == std::ios::goodbit);
63 ios.setstate(std::ios::eofbit);
64 assert(ios.rdstate() == std::ios::eofbit);
65 ios.setstate(std::ios::failbit);
66 assert(ios.rdstate() == (std::ios::eofbit | std::ios::failbit));
69 return 0;