1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <ostream> 11 12 // template <class charT, class traits = char_traits<charT> > 13 // class basic_ostream; 14 15 // basic_ostream& flush(); 16 17 #include <ostream> 18 #include <cassert> 19 20 int sync_called = 0; 21 22 template <class CharT> 23 class testbuf 24 : public std::basic_streambuf<CharT> 25 { 26 public: 27 testbuf() 28 { 29 } 30 31 protected: 32 33 virtual int 34 sync() 35 { 36 if (sync_called++ == 1) 37 return -1; 38 return 0; 39 } 40 }; 41 42 int main() 43 { 44 { 45 testbuf<char> sb; 46 std::ostream os(&sb); 47 os.flush(); 48 assert(os.good()); 49 assert(sync_called == 1); 50 os.flush(); 51 assert(os.bad()); 52 assert(sync_called == 2); 53 } 54 } 55