Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / output.streams / ostream.unformatted / flush.pass.cpp
blob6d91d714194640426d808c2791eb1bf565fb911e
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& flush();
16 #include <ostream>
17 #include <cassert>
19 #include "test_macros.h"
21 int sync_called = 0;
23 template <class CharT>
24 class testbuf
25 : public std::basic_streambuf<CharT>
27 public:
28 testbuf()
32 protected:
34 virtual int
35 sync()
37 if (sync_called++ == 1)
38 return -1;
39 return 0;
43 int main(int, char**)
46 testbuf<char> sb;
47 std::ostream os(&sb);
48 os.flush();
49 assert(os.good());
50 assert(sync_called == 1);
51 os.flush();
52 assert(os.bad());
53 assert(sync_called == 2);
56 return 0;