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