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 // void register_callback(event_callback fn, int index);
15 
16 #include <ios>
17 #include <string>
18 #include <locale>
19 #include <cassert>
20 
21 #include "platform_support.h" // locale name macros
22 
23 class test
24     : public std::ios
25 {
26 public:
test()27     test()
28     {
29         init(0);
30     }
31 };
32 
33 int f1_called = 0;
34 
f1(std::ios_base::event ev,std::ios_base & stream,int index)35 void f1(std::ios_base::event ev, std::ios_base& stream, int index)
36 {
37     if (ev == std::ios_base::imbue_event)
38     {
39         assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
40         assert(index == 4);
41         ++f1_called;
42     }
43 }
44 
main()45 int main()
46 {
47     test t;
48     std::ios_base& b = t;
49     b.register_callback(f1, 4);
50     b.register_callback(f1, 4);
51     b.register_callback(f1, 4);
52     std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8));
53     assert(f1_called == 3);
54 }
55