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 // XFAIL: libcpp-no-exceptions 11 // <ostream> 12 13 // template <class charT, class traits = char_traits<charT> > 14 // class basic_ostream::sentry; 15 16 // ~sentry(); 17 18 #include <ostream> 19 #include <cassert> 20 21 int sync_called = 0; 22 23 template <class CharT> 24 struct testbuf1 25 : public std::basic_streambuf<CharT> 26 { 27 testbuf1() {} 28 29 protected: 30 31 int virtual sync() 32 { 33 ++sync_called; 34 return 1; 35 } 36 }; 37 38 int main() 39 { 40 { 41 std::ostream os((std::streambuf*)0); 42 std::ostream::sentry s(os); 43 assert(!bool(s)); 44 } 45 assert(sync_called == 0); 46 { 47 testbuf1<char> sb; 48 std::ostream os(&sb); 49 std::ostream::sentry s(os); 50 assert(bool(s)); 51 } 52 assert(sync_called == 0); 53 { 54 testbuf1<char> sb; 55 std::ostream os(&sb); 56 std::ostream::sentry s(os); 57 assert(bool(s)); 58 unitbuf(os); 59 } 60 assert(sync_called == 1); 61 { 62 testbuf1<char> sb; 63 std::ostream os(&sb); 64 try 65 { 66 std::ostream::sentry s(os); 67 assert(bool(s)); 68 unitbuf(os); 69 throw 1; 70 } 71 catch (...) 72 { 73 } 74 assert(sync_called == 1); 75 } 76 } 77