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