blob: 112928ca0ce68d7c9ce1944848b64fc0c49483e5 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000010// <ostream>
11
12// template <class charT, class traits = char_traits<charT> >
13// class basic_ostream::sentry;
14
15// ~sentry();
16
17#include <ostream>
18#include <cassert>
19
20int sync_called = 0;
21
22template <class CharT>
23struct testbuf1
24 : public std::basic_streambuf<CharT>
25{
26 testbuf1() {}
27
28protected:
29
30 int virtual sync()
31 {
32 ++sync_called;
33 return 1;
34 }
35};
36
37int main()
38{
39 {
40 std::ostream os((std::streambuf*)0);
41 std::ostream::sentry s(os);
42 assert(!bool(s));
43 }
44 assert(sync_called == 0);
45 {
46 testbuf1<char> sb;
47 std::ostream os(&sb);
48 std::ostream::sentry s(os);
49 assert(bool(s));
50 }
51 assert(sync_called == 0);
52 {
53 testbuf1<char> sb;
54 std::ostream os(&sb);
55 std::ostream::sentry s(os);
56 assert(bool(s));
57 unitbuf(os);
58 }
59 assert(sync_called == 1);
60 {
61 testbuf1<char> sb;
62 std::ostream os(&sb);
63 try
64 {
65 std::ostream::sentry s(os);
66 assert(bool(s));
67 unitbuf(os);
68 throw 1;
69 }
70 catch (...)
71 {
72 }
73 assert(sync_called == 1);
74 }
75}