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::sentry; 13 14 // explicit sentry(basic_ostream<charT,traits>& os); 15 16 #include <ostream> 17 #include <cassert> 18 19 int sync_called = 0; 20 21 template <class CharT> 22 struct testbuf1 23 : public std::basic_streambuf<CharT> 24 { 25 testbuf1() {} 26 27 protected: 28 29 int virtual sync() 30 { 31 ++sync_called; 32 return 1; 33 } 34 }; 35 36 int main() 37 { 38 { 39 std::ostream os((std::streambuf*)0); 40 std::ostream::sentry s(os); 41 assert(!bool(s)); 42 } 43 { 44 testbuf1<char> sb; 45 std::ostream os(&sb); 46 std::ostream::sentry s(os); 47 assert(bool(s)); 48 } 49 { 50 testbuf1<char> sb; 51 std::ostream os(&sb); 52 testbuf1<char> sb2; 53 std::ostream os2(&sb2); 54 os.tie(&os2); 55 assert(sync_called == 0); 56 std::ostream::sentry s(os); 57 assert(bool(s)); 58 assert(sync_called == 1); 59 } 60 } 61