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