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 // <ios>
11 
12 // class ios_base
13 
14 // ~ios_base()
15 
16 #include <ios>
17 #include <string>
18 #include <locale>
19 #include <cassert>
20 
21 class test
22     : public std::ios
23 {
24 public:
25     test()
26     {
27         init(0);
28     }
29 };
30 
31 bool f1_called = false;
32 bool f2_called = false;
33 bool f3_called = false;
34 
35 void f1(std::ios_base::event ev, std::ios_base& stream, int index)
36 {
37     if (ev == std::ios_base::erase_event)
38     {
39         assert(!f1_called);
40         assert( f2_called);
41         assert( f3_called);
42         assert(stream.getloc().name() == "C");
43         assert(index == 4);
44         f1_called = true;
45     }
46 }
47 
48 void f2(std::ios_base::event ev, std::ios_base& stream, int index)
49 {
50     if (ev == std::ios_base::erase_event)
51     {
52         assert(!f1_called);
53         assert(!f2_called);
54         assert( f3_called);
55         assert(stream.getloc().name() == "C");
56         assert(index == 5);
57         f2_called = true;
58     }
59 }
60 
61 void f3(std::ios_base::event ev, std::ios_base& stream, int index)
62 {
63     if (ev == std::ios_base::erase_event)
64     {
65         assert(!f1_called);
66         assert(!f2_called);
67         assert(!f3_called);
68         assert(stream.getloc().name() == "C");
69         assert(index == 6);
70         f3_called = true;
71     }
72 }
73 
74 int main()
75 {
76     {
77         test t;
78         std::ios_base& b = t;
79         b.register_callback(f1, 4);
80         b.register_callback(f2, 5);
81         b.register_callback(f3, 6);
82     }
83     assert(f1_called);
84     assert(f2_called);
85     assert(f3_called);
86 }
87