[Arm] Fix generating code with UB in NeonEmitter (#121802)
[llvm-project.git] / libcxx / test / std / input.output / iostreams.base / ios / basic.ios.members / imbue.pass.cpp
blob579e04ab3b3c393e44c68949dbe7045089151346
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 //===----------------------------------------------------------------------===//
9 // REQUIRES: locale.en_US.UTF-8
11 // <ios>
13 // template <class charT, class traits> class basic_ios
15 // locale imbue(const locale& loc);
17 #include <ios>
18 #include <streambuf>
19 #include <cassert>
21 #include "test_macros.h"
22 #include "platform_support.h" // locale name macros
24 struct testbuf
25 : public std::streambuf
29 bool f1_called = false;
30 bool f2_called = false;
31 bool f3_called = false;
33 void f1(std::ios_base::event ev, std::ios_base& stream, int index)
35 if (ev == std::ios_base::imbue_event)
37 assert(!f1_called);
38 assert( f2_called);
39 assert( f3_called);
40 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
41 assert(index == 4);
42 f1_called = true;
46 void f2(std::ios_base::event ev, std::ios_base& stream, int index)
48 if (ev == std::ios_base::imbue_event)
50 assert(!f1_called);
51 assert(!f2_called);
52 assert( f3_called);
53 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
54 assert(index == 5);
55 f2_called = true;
59 void f3(std::ios_base::event ev, std::ios_base& stream, int index)
61 if (ev == std::ios_base::imbue_event)
63 assert(!f1_called);
64 assert(!f2_called);
65 assert(!f3_called);
66 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
67 assert(index == 6);
68 f3_called = true;
72 int main(int, char**)
75 std::ios ios(0);
76 ios.register_callback(f1, 4);
77 ios.register_callback(f2, 5);
78 ios.register_callback(f3, 6);
79 std::locale l = ios.imbue(std::locale(LOCALE_en_US_UTF_8));
80 assert(l.name() == std::string("C"));
81 assert(ios.getloc().name() == std::string(LOCALE_en_US_UTF_8));
82 assert(f1_called);
83 assert(f2_called);
84 assert(f3_called);
86 f1_called = false;
87 f2_called = false;
88 f3_called = false;
90 testbuf sb;
91 std::ios ios(&sb);
92 ios.register_callback(f1, 4);
93 ios.register_callback(f2, 5);
94 ios.register_callback(f3, 6);
95 std::locale l = ios.imbue(std::locale(LOCALE_en_US_UTF_8));
96 assert(l.name() == std::string("C"));
97 assert(ios.getloc().name() == std::string(LOCALE_en_US_UTF_8));
98 assert(sb.getloc().name() == std::string(LOCALE_en_US_UTF_8));
99 assert(f1_called);
100 assert(f2_called);
101 assert(f3_called);
104 return 0;