Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostreams.base / ios / basic.ios.members / set_rdbuf.pass.cpp
blob04b1b9ff6b04e07c5d547864298dd5e051a68f2c
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 set_rdbuf(basic_streambuf<charT, traits>* sb);
15 #include <ios>
16 #include <streambuf>
17 #include <cassert>
19 #include "test_macros.h"
21 struct testbuf
22 : public std::streambuf
26 struct testios
27 : public std::ios
29 testios(std::streambuf* p) : std::ios(p) {}
30 void set_rdbuf(std::streambuf* x) {std::ios::set_rdbuf(x);}
33 int main(int, char**)
35 testbuf sb1;
36 testbuf sb2;
37 testios ios(&sb1);
38 #ifndef TEST_HAS_NO_EXCEPTIONS
39 try
41 ios.setstate(std::ios::badbit);
42 ios.exceptions(std::ios::badbit);
43 assert(false);
45 catch (...)
48 #endif
49 ios.set_rdbuf(&sb2);
50 assert(ios.rdbuf() == &sb2);
51 #ifndef TEST_HAS_NO_EXCEPTIONS
52 try
54 ios.setstate(std::ios::badbit);
55 ios.exceptions(std::ios::badbit);
57 catch (...)
60 #endif
61 ios.set_rdbuf(0);
62 assert(ios.rdbuf() == 0);
64 return 0;