1
1
// Copyright (c) Microsoft Corporation.
2
2
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3
3
4
+ #define _SILENCE_CXX20_CODECVT_FACETS_DEPRECATION_WARNING
5
+
4
6
#include < cassert>
5
7
#include < cstdio>
6
8
#include < locale>
@@ -11,8 +13,8 @@ using namespace std;
11
13
12
14
#define STATIC_ASSERT (...) static_assert (__VA_ARGS__, #__VA_ARGS__)
13
15
14
- STATIC_ASSERT (noexcept (locale{} == locale{}));
15
- STATIC_ASSERT (noexcept (locale{} != locale{}));
16
+ STATIC_ASSERT (noexcept (locale{} == locale{})); // strengthened
17
+ STATIC_ASSERT (noexcept (locale{} != locale{})); // strengthened
16
18
17
19
void test_dll () {
18
20
puts (" Calling dll" );
@@ -50,8 +52,131 @@ void test_exe_part2() {
50
52
assert (!isspace (L' Z' , locale ()));
51
53
}
52
54
55
+ #ifndef _M_CEE_PURE
56
+ locale make_unnamed_locale () {
57
+ locale result{locale{" C" }, &use_facet<numpunct<char >>(locale{" C" })};
58
+ assert (result.name () == " *" );
59
+ return result;
60
+ }
61
+
62
+ template <class Facet >
63
+ void test_locale_name_with_facet_pointer_one () {
64
+ {
65
+ locale result{locale{" C" }, static_cast <Facet*>(nullptr )};
66
+ assert (result.name () == " C" );
67
+ }
68
+ {
69
+ locale result{make_unnamed_locale (), static_cast <Facet*>(nullptr )};
70
+ assert (result.name () == " *" );
71
+ }
72
+ {
73
+ locale le{" C" };
74
+ locale result{le, &use_facet<Facet>(le)};
75
+ assert (result.name () == " *" );
76
+ }
77
+ {
78
+ locale lunnamed{make_unnamed_locale ()};
79
+ locale result{lunnamed, &use_facet<Facet>(lunnamed)};
80
+ assert (result.name () == " *" );
81
+ }
82
+ }
83
+
84
+ void test_locale_name_with_facet_pointer_all () {
85
+ test_locale_name_with_facet_pointer_one<collate<char >>();
86
+ test_locale_name_with_facet_pointer_one<collate<wchar_t >>();
87
+
88
+ test_locale_name_with_facet_pointer_one<ctype<char >>();
89
+ test_locale_name_with_facet_pointer_one<ctype<wchar_t >>();
90
+ test_locale_name_with_facet_pointer_one<codecvt<char , char , mbstate_t >>();
91
+ test_locale_name_with_facet_pointer_one<codecvt<char16_t , char , mbstate_t >>();
92
+ test_locale_name_with_facet_pointer_one<codecvt<char32_t , char , mbstate_t >>();
93
+ #ifdef __cpp_char8_t
94
+ test_locale_name_with_facet_pointer_one<codecvt<char16_t , char8_t , mbstate_t >>();
95
+ test_locale_name_with_facet_pointer_one<codecvt<char32_t , char8_t , mbstate_t >>();
96
+ #endif // __cpp_char8_t
97
+ test_locale_name_with_facet_pointer_one<codecvt<wchar_t , char , mbstate_t >>();
98
+
99
+ test_locale_name_with_facet_pointer_one<moneypunct<char >>();
100
+ test_locale_name_with_facet_pointer_one<moneypunct<wchar_t >>();
101
+ test_locale_name_with_facet_pointer_one<moneypunct<char , true >>();
102
+ test_locale_name_with_facet_pointer_one<moneypunct<wchar_t , true >>();
103
+ test_locale_name_with_facet_pointer_one<money_get<char >>();
104
+ test_locale_name_with_facet_pointer_one<money_get<wchar_t >>();
105
+ test_locale_name_with_facet_pointer_one<money_put<char >>();
106
+ test_locale_name_with_facet_pointer_one<money_put<wchar_t >>();
107
+
108
+ test_locale_name_with_facet_pointer_one<numpunct<char >>();
109
+ test_locale_name_with_facet_pointer_one<numpunct<wchar_t >>();
110
+ test_locale_name_with_facet_pointer_one<num_get<char >>();
111
+ test_locale_name_with_facet_pointer_one<num_get<wchar_t >>();
112
+ test_locale_name_with_facet_pointer_one<num_put<char >>();
113
+ test_locale_name_with_facet_pointer_one<num_put<wchar_t >>();
114
+
115
+ test_locale_name_with_facet_pointer_one<time_get<char >>();
116
+ test_locale_name_with_facet_pointer_one<time_get<wchar_t >>();
117
+ test_locale_name_with_facet_pointer_one<time_put<char >>();
118
+ test_locale_name_with_facet_pointer_one<time_put<wchar_t >>();
119
+
120
+ test_locale_name_with_facet_pointer_one<messages<char >>();
121
+ test_locale_name_with_facet_pointer_one<messages<wchar_t >>();
122
+ }
123
+
124
+ void test_locale_name_with_another_locale_and_cats () {
125
+ locale lc{" C" };
126
+ locale lunnamed{make_unnamed_locale ()};
127
+ {
128
+ locale result{lc, lc, locale::none};
129
+ assert (result.name () != " *" );
130
+ }
131
+ {
132
+ locale result{lc, lunnamed, locale::none};
133
+ assert (result.name () != " *" );
134
+ }
135
+ {
136
+ locale result{lunnamed, lc, locale::none};
137
+ assert (result.name () == " *" );
138
+ }
139
+ {
140
+ locale result{lunnamed, lunnamed, locale::none};
141
+ assert (result.name () == " *" );
142
+ }
143
+
144
+ constexpr int cats_masks_count = 6 ; // collate | ctype | monetary | numeric | time | messages
145
+ for (int precats = 1 ; precats < (1 << cats_masks_count); ++precats) {
146
+ const locale::category cats = ((precats & (1 << 0 )) != 0 ? locale::collate : locale::none)
147
+ | ((precats & (1 << 1 )) != 0 ? locale::ctype : locale::none)
148
+ | ((precats & (1 << 2 )) != 0 ? locale::monetary : locale::none)
149
+ | ((precats & (1 << 3 )) != 0 ? locale::numeric : locale::none)
150
+ | ((precats & (1 << 4 )) != 0 ? locale::time : locale::none)
151
+ | ((precats & (1 << 5 )) != 0 ? locale::messages : locale::none);
152
+ {
153
+ locale result{lc, lc, cats};
154
+ assert (result.name () != " *" );
155
+ }
156
+ {
157
+ locale result{lc, lunnamed, cats};
158
+ assert (result.name () == " *" );
159
+ }
160
+ {
161
+ locale result{lunnamed, lc, cats};
162
+ assert (result.name () == " *" );
163
+ }
164
+ {
165
+ locale result{lunnamed, lunnamed, cats};
166
+ assert (result.name () == " *" );
167
+ }
168
+ }
169
+ }
170
+ #endif // _M_CEE_PURE
171
+
53
172
int main () {
54
173
test_exe_part1 ();
55
174
test_dll ();
56
175
test_exe_part2 ();
176
+
177
+ #ifndef _M_CEE_PURE
178
+ // test coverage for LWG-2295
179
+ test_locale_name_with_facet_pointer_all ();
180
+ test_locale_name_with_another_locale_and_cats ();
181
+ #endif // _M_CEE_PURE
57
182
}
0 commit comments