| 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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// <ostream> |
| 10 |
|
| 11 |
// template <class charT, class traits = char_traits<charT> > |
| 12 |
// class basic_ostream; |
| 13 |
|
| 14 |
// basic_ostream& flush(); |
| 15 |
|
| 16 |
#include <ostream> |
| 17 |
#include <cassert> |
| 18 |
|
| 19 |
#include "test_macros.h" |
| 20 |
|
| 21 |
int sync_called = 0; |
| 22 |
|
| 23 |
template <class CharT> |
| 24 |
class testbuf |
| 25 |
: public std::basic_streambuf<CharT> |
| 26 |
{ |
| 27 |
public: |
| 28 |
testbuf() |
| 29 |
{ |
| 30 |
} |
| 31 |
|
| 32 |
protected: |
| 33 |
|
| 34 |
virtual int |
| 35 |
sync() |
| 36 |
{ |
| 37 |
if (sync_called++ == 1) |
| 38 |
return -1; |
| 39 |
return 0; |
| 40 |
} |
| 41 |
}; |
| 42 |
|
| 43 |
int main(int, char**) |
| 44 |
{ |
| 45 |
{ |
| 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); |
| 54 |
} |
| 55 |
|
| 56 |
return 0; |
| 57 |
} |