1// Copyright (C) 1997-2022 Free Software Foundation, Inc.
2//
3// This file is part of the GNU ISO C++ Library.  This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// Under Section 7 of GPL version 3, you are granted additional
15// permissions described in the GCC Runtime Library Exception, version
16// 3.1, as published by the Free Software Foundation.
17
18// You should have received a copy of the GNU General Public License and
19// a copy of the GCC Runtime Library Exception along with this program;
20// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21// <http://www.gnu.org/licenses/>.
22
23#if __cplusplus != 201103L
24# error This file must be compiled as C++11
25#endif
26
27#define _GLIBCXX_USE_CXX11_ABI 1
28#include <clocale>
29#include <cstring>
30#include <cstdlib>     // For free.
31#include <cctype>
32#include <cwctype>     // For towupper, etc.
33#include <locale>
34#include <ext/atomicity.h>
35#include <ext/concurrence.h>
36
37#if _GLIBCXX_USE_DUAL_ABI
38// This file is compiled with the new std::string ABI so std::numpunct<char>
39// refers to std::__cxx11::numpunct<char>. These declarations let us refer
40// to the other facets instantiated with the old ABI.
41# define _GLIBCXX_LOC_ID(mangled) extern std::locale::id mangled
42_GLIBCXX_LOC_ID(_ZNSt8numpunctIcE2idE);
43_GLIBCXX_LOC_ID(_ZNSt7collateIcE2idE);
44_GLIBCXX_LOC_ID(_ZNSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
45_GLIBCXX_LOC_ID(_ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
46_GLIBCXX_LOC_ID(_ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
47_GLIBCXX_LOC_ID(_ZNSt10moneypunctIcLb0EE2idE);
48_GLIBCXX_LOC_ID(_ZNSt10moneypunctIcLb1EE2idE);
49_GLIBCXX_LOC_ID(_ZNSt8messagesIcE2idE);
50# ifdef _GLIBCXX_USE_WCHAR_T
51_GLIBCXX_LOC_ID(_ZNSt8numpunctIwE2idE);
52_GLIBCXX_LOC_ID(_ZNSt7collateIwE2idE);
53_GLIBCXX_LOC_ID(_ZNSt8time_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
54_GLIBCXX_LOC_ID(_ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
55_GLIBCXX_LOC_ID(_ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
56_GLIBCXX_LOC_ID(_ZNSt10moneypunctIwLb0EE2idE);
57_GLIBCXX_LOC_ID(_ZNSt10moneypunctIwLb1EE2idE);
58_GLIBCXX_LOC_ID(_ZNSt8messagesIwE2idE);
59# endif
60#endif
61
62
63namespace
64{
65  const int num_facets = (
66      _GLIBCXX_NUM_FACETS + _GLIBCXX_NUM_CXX11_FACETS
67#ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
68      + _GLIBCXX_NUM_LBDL_ALT128_FACETS
69#endif
70      )
71#ifdef _GLIBCXX_USE_WCHAR_T
72    * 2
73#endif
74    + _GLIBCXX_NUM_UNICODE_FACETS;
75
76  __gnu_cxx::__mutex&
77  get_locale_mutex()
78  {
79    static __gnu_cxx::__mutex locale_mutex;
80    return locale_mutex;
81  }
82
83  using namespace std;
84
85  typedef char fake_locale_Impl[sizeof(locale::_Impl)]
86  __attribute__ ((aligned(__alignof__(locale::_Impl))));
87  fake_locale_Impl c_locale_impl;
88
89  typedef char fake_locale[sizeof(locale)]
90  __attribute__ ((aligned(__alignof__(locale))));
91  fake_locale c_locale;
92
93  typedef char fake_name_vec[sizeof(char*)]
94  __attribute__ ((aligned(__alignof__(char*))));
95  fake_name_vec name_vec[6 + _GLIBCXX_NUM_CATEGORIES];
96
97  typedef char fake_names[sizeof(char[2])]
98  __attribute__ ((aligned(__alignof__(char[2]))));
99  fake_names name_c[6 + _GLIBCXX_NUM_CATEGORIES];
100
101  typedef char fake_facet_vec[sizeof(locale::facet*)]
102  __attribute__ ((aligned(__alignof__(locale::facet*))));
103  fake_facet_vec facet_vec[num_facets];
104
105  typedef char fake_cache_vec[sizeof(locale::facet*)]
106  __attribute__ ((aligned(__alignof__(locale::facet*))));
107  fake_cache_vec cache_vec[num_facets];
108
109  typedef char fake_ctype_c[sizeof(std::ctype<char>)]
110  __attribute__ ((aligned(__alignof__(std::ctype<char>))));
111  fake_ctype_c ctype_c;
112
113  typedef char fake_collate_c[sizeof(std::collate<char>)]
114  __attribute__ ((aligned(__alignof__(std::collate<char>))));
115  fake_collate_c collate_c;
116
117  typedef char fake_numpunct_c[sizeof(numpunct<char>)]
118  __attribute__ ((aligned(__alignof__(numpunct<char>))));
119  fake_numpunct_c numpunct_c;
120
121  typedef char fake_num_get_c[sizeof(num_get<char>)]
122  __attribute__ ((aligned(__alignof__(num_get<char>))));
123  fake_num_get_c num_get_c;
124
125  typedef char fake_num_put_c[sizeof(num_put<char>)]
126  __attribute__ ((aligned(__alignof__(num_put<char>))));
127  fake_num_put_c num_put_c;
128
129  typedef char fake_codecvt_c[sizeof(codecvt<char, char, mbstate_t>)]
130  __attribute__ ((aligned(__alignof__(codecvt<char, char, mbstate_t>))));
131  fake_codecvt_c codecvt_c;
132
133  typedef char fake_moneypunct_c[sizeof(moneypunct<char, true>)]
134  __attribute__ ((aligned(__alignof__(moneypunct<char, true>))));
135  fake_moneypunct_c moneypunct_ct;
136  fake_moneypunct_c moneypunct_cf;
137
138  typedef char fake_money_get_c[sizeof(money_get<char>)]
139  __attribute__ ((aligned(__alignof__(money_get<char>))));
140  fake_money_get_c money_get_c;
141
142  typedef char fake_money_put_c[sizeof(money_put<char>)]
143  __attribute__ ((aligned(__alignof__(money_put<char>))));
144  fake_money_put_c money_put_c;
145
146  typedef char fake_timepunct_c[sizeof(__timepunct<char>)]
147  __attribute__ ((aligned(__alignof__(__timepunct<char>))));
148  fake_timepunct_c timepunct_c;
149
150  typedef char fake_time_get_c[sizeof(time_get<char>)]
151  __attribute__ ((aligned(__alignof__(time_get<char>))));
152  fake_time_get_c time_get_c;
153
154  typedef char fake_time_put_c[sizeof(time_put<char>)]
155  __attribute__ ((aligned(__alignof__(time_put<char>))));
156  fake_time_put_c time_put_c;
157
158  typedef char fake_messages_c[sizeof(messages<char>)]
159  __attribute__ ((aligned(__alignof__(messages<char>))));
160  fake_messages_c messages_c;
161
162#ifdef  _GLIBCXX_USE_WCHAR_T
163  typedef char fake_wtype_w[sizeof(std::ctype<wchar_t>)]
164  __attribute__ ((aligned(__alignof__(std::ctype<wchar_t>))));
165  fake_wtype_w ctype_w;
166
167  typedef char fake_wollate_w[sizeof(std::collate<wchar_t>)]
168  __attribute__ ((aligned(__alignof__(std::collate<wchar_t>))));
169  fake_wollate_w collate_w;
170
171  typedef char fake_numpunct_w[sizeof(numpunct<wchar_t>)]
172  __attribute__ ((aligned(__alignof__(numpunct<wchar_t>))));
173  fake_numpunct_w numpunct_w;
174
175  typedef char fake_num_get_w[sizeof(num_get<wchar_t>)]
176  __attribute__ ((aligned(__alignof__(num_get<wchar_t>))));
177  fake_num_get_w num_get_w;
178
179  typedef char fake_num_put_w[sizeof(num_put<wchar_t>)]
180  __attribute__ ((aligned(__alignof__(num_put<wchar_t>))));
181  fake_num_put_w num_put_w;
182
183  typedef char fake_wodecvt_w[sizeof(codecvt<wchar_t, char, mbstate_t>)]
184  __attribute__ ((aligned(__alignof__(codecvt<wchar_t, char, mbstate_t>))));
185  fake_wodecvt_w codecvt_w;
186
187  typedef char fake_moneypunct_w[sizeof(moneypunct<wchar_t, true>)]
188  __attribute__ ((aligned(__alignof__(moneypunct<wchar_t, true>))));
189  fake_moneypunct_w moneypunct_wt;
190  fake_moneypunct_w moneypunct_wf;
191
192  typedef char fake_money_get_w[sizeof(money_get<wchar_t>)]
193  __attribute__ ((aligned(__alignof__(money_get<wchar_t>))));
194  fake_money_get_w money_get_w;
195
196  typedef char fake_money_put_w[sizeof(money_put<wchar_t>)]
197  __attribute__ ((aligned(__alignof__(money_put<wchar_t>))));
198  fake_money_put_w money_put_w;
199
200  typedef char fake_timepunct_w[sizeof(__timepunct<wchar_t>)]
201  __attribute__ ((aligned(__alignof__(__timepunct<wchar_t>))));
202  fake_timepunct_w timepunct_w;
203
204  typedef char fake_time_get_w[sizeof(time_get<wchar_t>)]
205  __attribute__ ((aligned(__alignof__(time_get<wchar_t>))));
206  fake_time_get_w time_get_w;
207
208  typedef char fake_time_put_w[sizeof(time_put<wchar_t>)]
209  __attribute__ ((aligned(__alignof__(time_put<wchar_t>))));
210  fake_time_put_w time_put_w;
211
212  typedef char fake_messages_w[sizeof(messages<wchar_t>)]
213  __attribute__ ((aligned(__alignof__(messages<wchar_t>))));
214  fake_messages_w messages_w;
215#endif
216
217  typedef char fake_codecvt_c16[sizeof(codecvt<char16_t, char, mbstate_t>)]
218  __attribute__ ((aligned(__alignof__(codecvt<char16_t, char, mbstate_t>))));
219  fake_codecvt_c16 codecvt_c16;
220
221  typedef char fake_codecvt_c32[sizeof(codecvt<char32_t, char, mbstate_t>)]
222  __attribute__ ((aligned(__alignof__(codecvt<char32_t, char, mbstate_t>))));
223  fake_codecvt_c32 codecvt_c32;
224
225#ifdef _GLIBCXX_USE_CHAR8_T
226  typedef char fake_codecvt_c16_c8[sizeof(codecvt<char16_t, char8_t, mbstate_t>)]
227  __attribute__ ((aligned(__alignof__(codecvt<char16_t, char8_t, mbstate_t>))));
228  fake_codecvt_c16_c8 codecvt_c16_c8;
229
230  typedef char fake_codecvt_c32_c8[sizeof(codecvt<char32_t, char8_t, mbstate_t>)]
231  __attribute__ ((aligned(__alignof__(codecvt<char32_t, char8_t, mbstate_t>))));
232  fake_codecvt_c32_c8 codecvt_c32_c8;
233#endif
234
235  // Storage for "C" locale caches.
236  typedef char fake_num_cache_c[sizeof(std::__numpunct_cache<char>)]
237  __attribute__ ((aligned(__alignof__(std::__numpunct_cache<char>))));
238  fake_num_cache_c numpunct_cache_c;
239
240  typedef char fake_money_cache_c[sizeof(std::__moneypunct_cache<char, true>)]
241  __attribute__ ((aligned(__alignof__(std::__moneypunct_cache<char, true>))));
242  fake_money_cache_c moneypunct_cache_ct;
243  fake_money_cache_c moneypunct_cache_cf;
244
245  typedef char fake_time_cache_c[sizeof(std::__timepunct_cache<char>)]
246  __attribute__ ((aligned(__alignof__(std::__timepunct_cache<char>))));
247  fake_time_cache_c timepunct_cache_c;
248
249#ifdef _GLIBCXX_USE_WCHAR_T
250  typedef char fake_num_cache_w[sizeof(std::__numpunct_cache<wchar_t>)]
251  __attribute__ ((aligned(__alignof__(std::__numpunct_cache<wchar_t>))));
252  fake_num_cache_w numpunct_cache_w;
253
254  typedef char fake_money_cache_w[sizeof(std::__moneypunct_cache<wchar_t,true>)]
255  __attribute__ ((aligned(__alignof__(std::__moneypunct_cache<wchar_t,true>))));
256  fake_money_cache_w moneypunct_cache_wt;
257  fake_money_cache_w moneypunct_cache_wf;
258
259  typedef char fake_time_cache_w[sizeof(std::__timepunct_cache<wchar_t>)]
260  __attribute__ ((aligned(__alignof__(std::__timepunct_cache<wchar_t>))));
261  fake_time_cache_w timepunct_cache_w;
262#endif
263} // anonymous namespace
264
265namespace std _GLIBCXX_VISIBILITY(default)
266{
267_GLIBCXX_BEGIN_NAMESPACE_VERSION
268
269  locale::locale() throw() : _M_impl(0)
270  {
271    _S_initialize();
272
273    // Checked locking to optimize the common case where _S_global
274    // still points to _S_classic (locale::_S_initialize_once()):
275    // - If they are the same, just increment the reference count and
276    //   we are done.  This effectively constructs a C locale object
277    //   identical to the static c_locale.
278    // - Otherwise, _S_global can and may be destroyed due to
279    //   locale::global() call on another thread, in which case we
280    //   fall back to lock protected access to both _S_global and
281    //   its reference count.
282    _M_impl = _S_global;
283    if (_M_impl != _S_classic)
284      {
285        __gnu_cxx::__scoped_lock sentry(get_locale_mutex());
286        _S_global->_M_add_reference();
287        _M_impl = _S_global;
288      }
289  }
290
291  locale
292  locale::global(const locale& __other)
293  {
294    _S_initialize();
295    _Impl* __old;
296    {
297      __gnu_cxx::__scoped_lock sentry(get_locale_mutex());
298      __old = _S_global;
299      if (__other._M_impl != _S_classic)
300	__other._M_impl->_M_add_reference();
301      _S_global = __other._M_impl;
302      const string __other_name = __other.name();
303      if (__other_name != "*")
304	setlocale(LC_ALL, __other_name.c_str());
305    }
306
307    // Reference count sanity check: one reference removed for the
308    // subsition of __other locale, one added by return-by-value. Net
309    // difference: zero. When the returned locale object's destructor
310    // is called, then the reference count is decremented and possibly
311    // destroyed.
312    return locale(__old);
313  }
314
315  const locale&
316  locale::classic()
317  {
318    _S_initialize();
319    return *(const locale*)c_locale;
320  }
321
322  void
323  locale::_S_initialize_once() throw()
324  {
325    // Need to check this because we could get called once from _S_initialize()
326    // when the program is single-threaded, and then again (via __gthread_once)
327    // when it's multi-threaded.
328    if (_S_classic)
329      return;
330
331    // 2 references.
332    // One reference for _S_classic, one for _S_global
333    _S_classic = new (&c_locale_impl) _Impl(2);
334    _S_global = _S_classic;
335    new (&c_locale) locale(_S_classic);
336  }
337
338  void
339  locale::_S_initialize()
340  {
341#ifdef __GTHREADS
342    if (!__gnu_cxx::__is_single_threaded())
343      __gthread_once(&_S_once, _S_initialize_once);
344#endif
345    if (__builtin_expect(!_S_classic, 0))
346      _S_initialize_once();
347  }
348
349  // Definitions for static const data members of locale::_Impl
350  const locale::id* const
351  locale::_Impl::_S_id_ctype[] =
352  {
353    &std::ctype<char>::id,
354    &codecvt<char, char, mbstate_t>::id,
355#ifdef _GLIBCXX_USE_WCHAR_T
356    &std::ctype<wchar_t>::id,
357    &codecvt<wchar_t, char, mbstate_t>::id,
358#endif
359#if _GLIBCXX_NUM_UNICODE_FACETS != 0
360    &codecvt<char16_t, char, mbstate_t>::id,
361    &codecvt<char32_t, char, mbstate_t>::id,
362#ifdef _GLIBCXX_USE_CHAR8_T
363    &codecvt<char16_t, char8_t, mbstate_t>::id,
364    &codecvt<char32_t, char8_t, mbstate_t>::id,
365#endif
366#endif
367    0
368  };
369
370  const locale::id* const
371  locale::_Impl::_S_id_numeric[] =
372  {
373    &num_get<char>::id,
374    &num_put<char>::id,
375    &numpunct<char>::id,
376#ifdef _GLIBCXX_USE_WCHAR_T
377    &num_get<wchar_t>::id,
378    &num_put<wchar_t>::id,
379    &numpunct<wchar_t>::id,
380#endif
381    0
382  };
383
384  const locale::id* const
385  locale::_Impl::_S_id_collate[] =
386  {
387    &std::collate<char>::id,
388#ifdef _GLIBCXX_USE_WCHAR_T
389    &std::collate<wchar_t>::id,
390#endif
391    0
392  };
393
394  const locale::id* const
395  locale::_Impl::_S_id_time[] =
396  {
397    &__timepunct<char>::id,
398    &time_get<char>::id,
399    &time_put<char>::id,
400#ifdef _GLIBCXX_USE_WCHAR_T
401    &__timepunct<wchar_t>::id,
402    &time_get<wchar_t>::id,
403    &time_put<wchar_t>::id,
404#endif
405    0
406  };
407
408  const locale::id* const
409  locale::_Impl::_S_id_monetary[] =
410  {
411    &money_get<char>::id,
412    &money_put<char>::id,
413    &moneypunct<char, false>::id,
414    &moneypunct<char, true >::id,
415#ifdef _GLIBCXX_USE_WCHAR_T
416    &money_get<wchar_t>::id,
417    &money_put<wchar_t>::id,
418    &moneypunct<wchar_t, false>::id,
419    &moneypunct<wchar_t, true >::id,
420#endif
421    0
422  };
423
424  const locale::id* const
425  locale::_Impl::_S_id_messages[] =
426  {
427    &std::messages<char>::id,
428#ifdef _GLIBCXX_USE_WCHAR_T
429    &std::messages<wchar_t>::id,
430#endif
431    0
432  };
433
434  const locale::id* const* const
435  locale::_Impl::_S_facet_categories[] =
436  {
437    // Order must match the decl order in class locale.
438    locale::_Impl::_S_id_ctype,
439    locale::_Impl::_S_id_numeric,
440    locale::_Impl::_S_id_collate,
441    locale::_Impl::_S_id_time,
442    locale::_Impl::_S_id_monetary,
443    locale::_Impl::_S_id_messages,
444    0
445  };
446
447#if _GLIBCXX_USE_DUAL_ABI
448  // Facets that are instantiated for both the COW and SSO std::string ABIs.
449  // The COW ABI version must come first, followed by its SSO twin.
450  const locale::id* const locale::_S_twinned_facets[] = {
451    &::_ZNSt8numpunctIcE2idE,
452    &numpunct<char>::id,
453    &::_ZNSt7collateIcE2idE,
454    &std::collate<char>::id,
455    &::_ZNSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE,
456    &time_get<char>::id,
457    &::_ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE,
458    &money_get<char>::id,
459    &::_ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE,
460    &money_put<char>::id,
461    &::_ZNSt10moneypunctIcLb0EE2idE,
462    &moneypunct<char, false>::id,
463    &::_ZNSt10moneypunctIcLb1EE2idE,
464    &moneypunct<char, true >::id,
465    &::_ZNSt8messagesIcE2idE,
466    &std::messages<char>::id,
467# ifdef _GLIBCXX_USE_WCHAR_T
468    &::_ZNSt8numpunctIwE2idE,
469    &numpunct<wchar_t>::id,
470    &::_ZNSt7collateIwE2idE,
471    &std::collate<wchar_t>::id,
472    &::_ZNSt8time_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE,
473    &time_get<wchar_t>::id,
474    &::_ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE,
475    &money_get<wchar_t>::id,
476    &::_ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE,
477    &money_put<wchar_t>::id,
478    &::_ZNSt10moneypunctIwLb0EE2idE,
479    &moneypunct<wchar_t, false>::id,
480    &::_ZNSt10moneypunctIwLb1EE2idE,
481    &moneypunct<wchar_t, true >::id,
482    &::_ZNSt8messagesIwE2idE,
483    &std::messages<wchar_t>::id,
484# endif
485    0, 0
486  };
487#endif
488
489  // Construct "C" _Impl.
490  locale::_Impl::
491  _Impl(size_t __refs) throw()
492  : _M_refcount(__refs), _M_facets(0), _M_facets_size(num_facets),
493  _M_caches(0), _M_names(0)
494  {
495    _M_facets = new (&facet_vec) const facet*[_M_facets_size]();
496    _M_caches = new (&cache_vec) const facet*[_M_facets_size]();
497
498    // Name the categories.
499    _M_names = new (&name_vec) char*[_S_categories_size]();
500    _M_names[0] = new (&name_c[0]) char[2];
501    std::memcpy(_M_names[0], locale::facet::_S_get_c_name(), 2);
502
503    // This is needed as presently the C++ version of "C" locales
504    // != data in the underlying locale model for __timepunct,
505    // numpunct, and moneypunct. Also, the "C" locales must be
506    // constructed in a way such that they are pre-allocated.
507    // NB: Set locale::facets(ref) count to one so that each individual
508    // facet is not destroyed when the locale (and thus locale::_Impl) is
509    // destroyed.
510    _M_init_facet(new (&ctype_c) std::ctype<char>(0, false, 1));
511    _M_init_facet(new (&codecvt_c) codecvt<char, char, mbstate_t>(1));
512
513    typedef __numpunct_cache<char> num_cache_c;
514    num_cache_c* __npc = new (&numpunct_cache_c) num_cache_c(2);
515    _M_init_facet(new (&numpunct_c) numpunct<char>(__npc, 1));
516
517    _M_init_facet(new (&num_get_c) num_get<char>(1));
518    _M_init_facet(new (&num_put_c) num_put<char>(1));
519    _M_init_facet(new (&collate_c) std::collate<char>(1));
520
521    typedef __moneypunct_cache<char, false> money_cache_cf;
522    typedef __moneypunct_cache<char, true> money_cache_ct;
523    money_cache_cf* __mpcf = new (&moneypunct_cache_cf) money_cache_cf(2);
524    _M_init_facet(new (&moneypunct_cf) moneypunct<char, false>(__mpcf, 1));
525    money_cache_ct* __mpct = new (&moneypunct_cache_ct) money_cache_ct(2);
526    _M_init_facet(new (&moneypunct_ct) moneypunct<char, true>(__mpct, 1));
527
528    _M_init_facet(new (&money_get_c) money_get<char>(1));
529    _M_init_facet(new (&money_put_c) money_put<char>(1));
530
531    typedef __timepunct_cache<char> time_cache_c;
532    time_cache_c* __tpc = new (&timepunct_cache_c) time_cache_c(2);
533    _M_init_facet(new (&timepunct_c) __timepunct<char>(__tpc, 1));
534
535    _M_init_facet(new (&time_get_c) time_get<char>(1));
536    _M_init_facet(new (&time_put_c) time_put<char>(1));
537    _M_init_facet(new (&messages_c) std::messages<char>(1));
538
539#ifdef  _GLIBCXX_USE_WCHAR_T
540    _M_init_facet(new (&ctype_w) std::ctype<wchar_t>(1));
541    _M_init_facet(new (&codecvt_w) codecvt<wchar_t, char, mbstate_t>(1));
542
543    typedef __numpunct_cache<wchar_t> num_cache_w;
544    num_cache_w* __npw = new (&numpunct_cache_w) num_cache_w(2);
545    _M_init_facet(new (&numpunct_w) numpunct<wchar_t>(__npw, 1));
546
547    _M_init_facet(new (&num_get_w) num_get<wchar_t>(1));
548    _M_init_facet(new (&num_put_w) num_put<wchar_t>(1));
549    _M_init_facet(new (&collate_w) std::collate<wchar_t>(1));
550
551    typedef __moneypunct_cache<wchar_t, false> money_cache_wf;
552    typedef __moneypunct_cache<wchar_t, true> money_cache_wt;
553    money_cache_wf* __mpwf = new (&moneypunct_cache_wf) money_cache_wf(2);
554    _M_init_facet(new (&moneypunct_wf) moneypunct<wchar_t, false>(__mpwf, 1));
555    money_cache_wt* __mpwt = new (&moneypunct_cache_wt) money_cache_wt(2);
556    _M_init_facet(new (&moneypunct_wt) moneypunct<wchar_t, true>(__mpwt, 1));
557
558    _M_init_facet(new (&money_get_w) money_get<wchar_t>(1));
559    _M_init_facet(new (&money_put_w) money_put<wchar_t>(1));
560
561    typedef __timepunct_cache<wchar_t> time_cache_w;
562    time_cache_w* __tpw = new (&timepunct_cache_w) time_cache_w(2);
563    _M_init_facet(new (&timepunct_w) __timepunct<wchar_t>(__tpw, 1));
564
565    _M_init_facet(new (&time_get_w) time_get<wchar_t>(1));
566    _M_init_facet(new (&time_put_w) time_put<wchar_t>(1));
567    _M_init_facet(new (&messages_w) std::messages<wchar_t>(1));
568#endif
569
570#if _GLIBCXX_NUM_UNICODE_FACETS != 0
571    _M_init_facet(new (&codecvt_c16) codecvt<char16_t, char, mbstate_t>(1));
572    _M_init_facet(new (&codecvt_c32) codecvt<char32_t, char, mbstate_t>(1));
573
574#ifdef _GLIBCXX_USE_CHAR8_T
575    _M_init_facet(new (&codecvt_c16_c8) codecvt<char16_t, char8_t, mbstate_t>(1));
576    _M_init_facet(new (&codecvt_c32_c8) codecvt<char32_t, char8_t, mbstate_t>(1));
577#endif
578
579#endif
580
581#ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
582    _M_init_extra_ldbl128(true);
583#endif
584
585#if _GLIBCXX_USE_DUAL_ABI
586    facet* extra[] = { __npc, __mpcf, __mpct
587# ifdef  _GLIBCXX_USE_WCHAR_T
588        , __npw, __mpwf, __mpwt
589# endif
590    };
591
592    // This call must be after creating all facets, as it sets caches.
593    _M_init_extra(extra);
594#endif
595
596    // This locale is safe to pre-cache, after all the facets have
597    // been created and installed.
598    _M_caches[numpunct<char>::id._M_id()] = __npc;
599    _M_caches[moneypunct<char, false>::id._M_id()] = __mpcf;
600    _M_caches[moneypunct<char, true>::id._M_id()] = __mpct;
601    _M_caches[__timepunct<char>::id._M_id()] = __tpc;
602#ifdef  _GLIBCXX_USE_WCHAR_T
603    _M_caches[numpunct<wchar_t>::id._M_id()] = __npw;
604    _M_caches[moneypunct<wchar_t, false>::id._M_id()] = __mpwf;
605    _M_caches[moneypunct<wchar_t, true>::id._M_id()] = __mpwt;
606    _M_caches[__timepunct<wchar_t>::id._M_id()] = __tpw;
607#endif
608  }
609
610_GLIBCXX_END_NAMESPACE_VERSION
611} // namespace
612