xref: /openbsd-src/gnu/gcc/libstdc++-v3/src/locale.cc (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
2*404b540aSrobert // Free Software Foundation, Inc.
3*404b540aSrobert //
4*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
5*404b540aSrobert // software; you can redistribute it and/or modify it under the
6*404b540aSrobert // terms of the GNU General Public License as published by the
7*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
8*404b540aSrobert // any later version.
9*404b540aSrobert 
10*404b540aSrobert // This library is distributed in the hope that it will be useful,
11*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
12*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*404b540aSrobert // GNU General Public License for more details.
14*404b540aSrobert 
15*404b540aSrobert // You should have received a copy of the GNU General Public License along
16*404b540aSrobert // with this library; see the file COPYING.  If not, write to the Free
17*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18*404b540aSrobert // USA.
19*404b540aSrobert 
20*404b540aSrobert // As a special exception, you may use this file as part of a free software
21*404b540aSrobert // library without restriction.  Specifically, if other files instantiate
22*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
23*404b540aSrobert // this file and link it with other files to produce an executable, this
24*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
25*404b540aSrobert // the GNU General Public License.  This exception does not however
26*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
27*404b540aSrobert // the GNU General Public License.
28*404b540aSrobert 
29*404b540aSrobert #include <clocale>
30*404b540aSrobert #include <cstring>
31*404b540aSrobert #include <cstdlib>     // For getenv
32*404b540aSrobert #include <cctype>
33*404b540aSrobert #include <cwctype>     // For towupper, etc.
34*404b540aSrobert #include <locale>
35*404b540aSrobert #include <ext/concurrence.h>
36*404b540aSrobert 
37*404b540aSrobert namespace
38*404b540aSrobert {
39*404b540aSrobert   __gnu_cxx::__mutex locale_cache_mutex;
40*404b540aSrobert } // anonymous namespace
41*404b540aSrobert 
42*404b540aSrobert // XXX GLIBCXX_ABI Deprecated
43*404b540aSrobert #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
44*404b540aSrobert # define _GLIBCXX_LOC_ID(mangled) extern std::locale::id mangled
45*404b540aSrobert _GLIBCXX_LOC_ID (_ZNSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
46*404b540aSrobert _GLIBCXX_LOC_ID (_ZNSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
47*404b540aSrobert _GLIBCXX_LOC_ID (_ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
48*404b540aSrobert _GLIBCXX_LOC_ID (_ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
49*404b540aSrobert # ifdef _GLIBCXX_USE_WCHAR_T
50*404b540aSrobert _GLIBCXX_LOC_ID (_ZNSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
51*404b540aSrobert _GLIBCXX_LOC_ID (_ZNSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
52*404b540aSrobert _GLIBCXX_LOC_ID (_ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
53*404b540aSrobert _GLIBCXX_LOC_ID (_ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
54*404b540aSrobert # endif
55*404b540aSrobert #endif
56*404b540aSrobert 
57*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
58*404b540aSrobert 
59*404b540aSrobert   // Definitions for static const data members of locale.
60*404b540aSrobert   const locale::category 	locale::none;
61*404b540aSrobert   const locale::category 	locale::ctype;
62*404b540aSrobert   const locale::category 	locale::numeric;
63*404b540aSrobert   const locale::category 	locale::collate;
64*404b540aSrobert   const locale::category 	locale::time;
65*404b540aSrobert   const locale::category 	locale::monetary;
66*404b540aSrobert   const locale::category 	locale::messages;
67*404b540aSrobert   const locale::category 	locale::all;
68*404b540aSrobert 
69*404b540aSrobert   // These are no longer exported.
70*404b540aSrobert   locale::_Impl*                locale::_S_classic;
71*404b540aSrobert   locale::_Impl* 		locale::_S_global;
72*404b540aSrobert 
73*404b540aSrobert #ifdef __GTHREADS
74*404b540aSrobert   __gthread_once_t 		locale::_S_once = __GTHREAD_ONCE_INIT;
75*404b540aSrobert #endif
76*404b540aSrobert 
locale(const locale & __other)77*404b540aSrobert   locale::locale(const locale& __other) throw()
78*404b540aSrobert   : _M_impl(__other._M_impl)
79*404b540aSrobert   { _M_impl->_M_add_reference(); }
80*404b540aSrobert 
81*404b540aSrobert   // This is used to initialize global and classic locales, and
82*404b540aSrobert   // assumes that the _Impl objects are constructed correctly.
83*404b540aSrobert   // The lack of a reference increment is intentional.
locale(_Impl * __ip)84*404b540aSrobert   locale::locale(_Impl* __ip) throw() : _M_impl(__ip)
85*404b540aSrobert   { }
86*404b540aSrobert 
~locale()87*404b540aSrobert   locale::~locale() throw()
88*404b540aSrobert   { _M_impl->_M_remove_reference(); }
89*404b540aSrobert 
90*404b540aSrobert   bool
operator ==(const locale & __rhs) const91*404b540aSrobert   locale::operator==(const locale& __rhs) const throw()
92*404b540aSrobert   {
93*404b540aSrobert     // Deal first with the common cases, fast to process: refcopies,
94*404b540aSrobert     // unnamed (i.e., !_M_names[0]), "simple" (!_M_names[1] => all the
95*404b540aSrobert     // categories same name, i.e., _M_names[0]). Otherwise fall back
96*404b540aSrobert     // to the general locale::name().
97*404b540aSrobert     bool __ret;
98*404b540aSrobert     if (_M_impl == __rhs._M_impl)
99*404b540aSrobert       __ret = true;
100*404b540aSrobert     else if (!_M_impl->_M_names[0] || !__rhs._M_impl->_M_names[0]
101*404b540aSrobert 	     || std::strcmp(_M_impl->_M_names[0],
102*404b540aSrobert 			    __rhs._M_impl->_M_names[0]) != 0)
103*404b540aSrobert       __ret = false;
104*404b540aSrobert     else if (!_M_impl->_M_names[1] && !__rhs._M_impl->_M_names[1])
105*404b540aSrobert       __ret = true;
106*404b540aSrobert     else
107*404b540aSrobert       __ret = this->name() == __rhs.name();
108*404b540aSrobert     return __ret;
109*404b540aSrobert   }
110*404b540aSrobert 
111*404b540aSrobert   const locale&
operator =(const locale & __other)112*404b540aSrobert   locale::operator=(const locale& __other) throw()
113*404b540aSrobert   {
114*404b540aSrobert     __other._M_impl->_M_add_reference();
115*404b540aSrobert     _M_impl->_M_remove_reference();
116*404b540aSrobert     _M_impl = __other._M_impl;
117*404b540aSrobert     return *this;
118*404b540aSrobert   }
119*404b540aSrobert 
120*404b540aSrobert   string
name() const121*404b540aSrobert   locale::name() const
122*404b540aSrobert   {
123*404b540aSrobert     string __ret;
124*404b540aSrobert     if (!_M_impl->_M_names[0])
125*404b540aSrobert       __ret = '*';
126*404b540aSrobert     else if (_M_impl->_M_check_same_name())
127*404b540aSrobert       __ret = _M_impl->_M_names[0];
128*404b540aSrobert     else
129*404b540aSrobert       {
130*404b540aSrobert 	__ret.reserve(128);
131*404b540aSrobert 	__ret += _S_categories[0];
132*404b540aSrobert 	__ret += '=';
133*404b540aSrobert 	__ret += _M_impl->_M_names[0];
134*404b540aSrobert 	for (size_t __i = 1; __i < _S_categories_size; ++__i)
135*404b540aSrobert 	  {
136*404b540aSrobert 	    __ret += ';';
137*404b540aSrobert 	    __ret += _S_categories[__i];
138*404b540aSrobert 	    __ret += '=';
139*404b540aSrobert 	    __ret += _M_impl->_M_names[__i];
140*404b540aSrobert 	  }
141*404b540aSrobert       }
142*404b540aSrobert     return __ret;
143*404b540aSrobert   }
144*404b540aSrobert 
145*404b540aSrobert   locale::category
_S_normalize_category(category __cat)146*404b540aSrobert   locale::_S_normalize_category(category __cat)
147*404b540aSrobert   {
148*404b540aSrobert     int __ret = 0;
149*404b540aSrobert     if (__cat == none || (__cat & all) && !(__cat & ~all))
150*404b540aSrobert       __ret = __cat;
151*404b540aSrobert     else
152*404b540aSrobert       {
153*404b540aSrobert 	// NB: May be a C-style "LC_ALL" category; convert.
154*404b540aSrobert 	switch (__cat)
155*404b540aSrobert 	  {
156*404b540aSrobert 	  case LC_COLLATE:
157*404b540aSrobert 	    __ret = collate;
158*404b540aSrobert 	    break;
159*404b540aSrobert 	  case LC_CTYPE:
160*404b540aSrobert 	    __ret = ctype;
161*404b540aSrobert 	    break;
162*404b540aSrobert 	  case LC_MONETARY:
163*404b540aSrobert 	    __ret = monetary;
164*404b540aSrobert 	    break;
165*404b540aSrobert 	  case LC_NUMERIC:
166*404b540aSrobert 	    __ret = numeric;
167*404b540aSrobert 	    break;
168*404b540aSrobert 	  case LC_TIME:
169*404b540aSrobert 	    __ret = time;
170*404b540aSrobert 	    break;
171*404b540aSrobert #ifdef _GLIBCXX_HAVE_LC_MESSAGES
172*404b540aSrobert 	  case LC_MESSAGES:
173*404b540aSrobert 	    __ret = messages;
174*404b540aSrobert 	    break;
175*404b540aSrobert #endif
176*404b540aSrobert 	  case LC_ALL:
177*404b540aSrobert 	    __ret = all;
178*404b540aSrobert 	    break;
179*404b540aSrobert 	  default:
180*404b540aSrobert 	    __throw_runtime_error(__N("locale::_S_normalize_category "
181*404b540aSrobert 				  "category not found"));
182*404b540aSrobert 	  }
183*404b540aSrobert       }
184*404b540aSrobert     return __ret;
185*404b540aSrobert   }
186*404b540aSrobert 
187*404b540aSrobert   // locale::facet
188*404b540aSrobert   __c_locale locale::facet::_S_c_locale;
189*404b540aSrobert 
190*404b540aSrobert   const char locale::facet::_S_c_name[2] = "C";
191*404b540aSrobert 
192*404b540aSrobert #ifdef __GTHREADS
193*404b540aSrobert   __gthread_once_t locale::facet::_S_once = __GTHREAD_ONCE_INIT;
194*404b540aSrobert #endif
195*404b540aSrobert 
196*404b540aSrobert   void
_S_initialize_once()197*404b540aSrobert   locale::facet::_S_initialize_once()
198*404b540aSrobert   {
199*404b540aSrobert     // Initialize the underlying locale model.
200*404b540aSrobert     _S_create_c_locale(_S_c_locale, _S_c_name);
201*404b540aSrobert   }
202*404b540aSrobert 
203*404b540aSrobert   __c_locale
_S_get_c_locale()204*404b540aSrobert   locale::facet::_S_get_c_locale()
205*404b540aSrobert   {
206*404b540aSrobert #ifdef __GHTREADS
207*404b540aSrobert     if (__gthread_active_p())
208*404b540aSrobert       __gthread_once(&_S_once, _S_initialize_once);
209*404b540aSrobert     else
210*404b540aSrobert #endif
211*404b540aSrobert       {
212*404b540aSrobert 	if (!_S_c_locale)
213*404b540aSrobert 	  _S_initialize_once();
214*404b540aSrobert       }
215*404b540aSrobert     return _S_c_locale;
216*404b540aSrobert   }
217*404b540aSrobert 
218*404b540aSrobert   const char*
_S_get_c_name()219*404b540aSrobert   locale::facet::_S_get_c_name()
220*404b540aSrobert   { return _S_c_name; }
221*404b540aSrobert 
222*404b540aSrobert   locale::facet::
~facet()223*404b540aSrobert   ~facet() { }
224*404b540aSrobert 
225*404b540aSrobert   // locale::_Impl
226*404b540aSrobert   locale::_Impl::
~_Impl()227*404b540aSrobert   ~_Impl() throw()
228*404b540aSrobert   {
229*404b540aSrobert     if (_M_facets)
230*404b540aSrobert       for (size_t __i = 0; __i < _M_facets_size; ++__i)
231*404b540aSrobert 	if (_M_facets[__i])
232*404b540aSrobert 	  _M_facets[__i]->_M_remove_reference();
233*404b540aSrobert     delete [] _M_facets;
234*404b540aSrobert 
235*404b540aSrobert     if (_M_caches)
236*404b540aSrobert       for (size_t __i = 0; __i < _M_facets_size; ++__i)
237*404b540aSrobert 	if (_M_caches[__i])
238*404b540aSrobert 	  _M_caches[__i]->_M_remove_reference();
239*404b540aSrobert     delete [] _M_caches;
240*404b540aSrobert 
241*404b540aSrobert     if (_M_names)
242*404b540aSrobert       for (size_t __i = 0; __i < _S_categories_size; ++__i)
243*404b540aSrobert 	delete [] _M_names[__i];
244*404b540aSrobert     delete [] _M_names;
245*404b540aSrobert   }
246*404b540aSrobert 
247*404b540aSrobert   // Clone existing _Impl object.
248*404b540aSrobert   locale::_Impl::
_Impl(const _Impl & __imp,size_t __refs)249*404b540aSrobert   _Impl(const _Impl& __imp, size_t __refs)
250*404b540aSrobert   : _M_refcount(__refs), _M_facets(0), _M_facets_size(__imp._M_facets_size),
251*404b540aSrobert   _M_caches(0), _M_names(0)
252*404b540aSrobert   {
253*404b540aSrobert     try
254*404b540aSrobert       {
255*404b540aSrobert 	_M_facets = new const facet*[_M_facets_size];
256*404b540aSrobert 	for (size_t __i = 0; __i < _M_facets_size; ++__i)
257*404b540aSrobert 	  {
258*404b540aSrobert 	    _M_facets[__i] = __imp._M_facets[__i];
259*404b540aSrobert 	    if (_M_facets[__i])
260*404b540aSrobert 	      _M_facets[__i]->_M_add_reference();
261*404b540aSrobert 	  }
262*404b540aSrobert 	_M_caches = new const facet*[_M_facets_size];
263*404b540aSrobert 	for (size_t __j = 0; __j < _M_facets_size; ++__j)
264*404b540aSrobert 	  {
265*404b540aSrobert 	    _M_caches[__j] = __imp._M_caches[__j];
266*404b540aSrobert 	    if (_M_caches[__j])
267*404b540aSrobert 	      _M_caches[__j]->_M_add_reference();
268*404b540aSrobert 	  }
269*404b540aSrobert 	_M_names = new char*[_S_categories_size];
270*404b540aSrobert 	for (size_t __k = 0; __k < _S_categories_size; ++__k)
271*404b540aSrobert 	  _M_names[__k] = 0;
272*404b540aSrobert 
273*404b540aSrobert 	// Name the categories.
274*404b540aSrobert 	for (size_t __l = 0; (__l < _S_categories_size
275*404b540aSrobert 			      && __imp._M_names[__l]); ++__l)
276*404b540aSrobert 	  {
277*404b540aSrobert 	    const size_t __len = std::strlen(__imp._M_names[__l]) + 1;
278*404b540aSrobert 	    _M_names[__l] = new char[__len];
279*404b540aSrobert 	    std::memcpy(_M_names[__l], __imp._M_names[__l], __len);
280*404b540aSrobert 	  }
281*404b540aSrobert       }
282*404b540aSrobert     catch(...)
283*404b540aSrobert       {
284*404b540aSrobert 	this->~_Impl();
285*404b540aSrobert 	__throw_exception_again;
286*404b540aSrobert       }
287*404b540aSrobert   }
288*404b540aSrobert 
289*404b540aSrobert   void
290*404b540aSrobert   locale::_Impl::
_M_replace_category(const _Impl * __imp,const locale::id * const * __idpp)291*404b540aSrobert   _M_replace_category(const _Impl* __imp,
292*404b540aSrobert 		      const locale::id* const* __idpp)
293*404b540aSrobert   {
294*404b540aSrobert     for (; *__idpp; ++__idpp)
295*404b540aSrobert       _M_replace_facet(__imp, *__idpp);
296*404b540aSrobert   }
297*404b540aSrobert 
298*404b540aSrobert   void
299*404b540aSrobert   locale::_Impl::
_M_replace_facet(const _Impl * __imp,const locale::id * __idp)300*404b540aSrobert   _M_replace_facet(const _Impl* __imp, const locale::id* __idp)
301*404b540aSrobert   {
302*404b540aSrobert     size_t __index = __idp->_M_id();
303*404b540aSrobert     if ((__index > (__imp->_M_facets_size - 1))
304*404b540aSrobert 	|| !__imp->_M_facets[__index])
305*404b540aSrobert       __throw_runtime_error(__N("locale::_Impl::_M_replace_facet"));
306*404b540aSrobert     _M_install_facet(__idp, __imp->_M_facets[__index]);
307*404b540aSrobert   }
308*404b540aSrobert 
309*404b540aSrobert   void
310*404b540aSrobert   locale::_Impl::
_M_install_facet(const locale::id * __idp,const facet * __fp)311*404b540aSrobert   _M_install_facet(const locale::id* __idp, const facet* __fp)
312*404b540aSrobert   {
313*404b540aSrobert     if (__fp)
314*404b540aSrobert       {
315*404b540aSrobert 	size_t __index = __idp->_M_id();
316*404b540aSrobert 
317*404b540aSrobert 	// Check size of facet vector to ensure adequate room.
318*404b540aSrobert 	if (__index > _M_facets_size - 1)
319*404b540aSrobert 	  {
320*404b540aSrobert 	    const size_t __new_size = __index + 4;
321*404b540aSrobert 
322*404b540aSrobert 	    // New facet array.
323*404b540aSrobert 	    const facet** __oldf = _M_facets;
324*404b540aSrobert 	    const facet** __newf;
325*404b540aSrobert 	    __newf = new const facet*[__new_size];
326*404b540aSrobert 	    for (size_t __i = 0; __i < _M_facets_size; ++__i)
327*404b540aSrobert 	      __newf[__i] = _M_facets[__i];
328*404b540aSrobert 	    for (size_t __l = _M_facets_size; __l < __new_size; ++__l)
329*404b540aSrobert 	      __newf[__l] = 0;
330*404b540aSrobert 
331*404b540aSrobert 	    // New cache array.
332*404b540aSrobert 	    const facet** __oldc = _M_caches;
333*404b540aSrobert 	    const facet** __newc;
334*404b540aSrobert 	    try
335*404b540aSrobert 	      {
336*404b540aSrobert 		__newc = new const facet*[__new_size];
337*404b540aSrobert 	      }
338*404b540aSrobert 	    catch(...)
339*404b540aSrobert 	      {
340*404b540aSrobert 		delete [] __newf;
341*404b540aSrobert 		__throw_exception_again;
342*404b540aSrobert 	      }
343*404b540aSrobert 	    for (size_t __j = 0; __j < _M_facets_size; ++__j)
344*404b540aSrobert 	      __newc[__j] = _M_caches[__j];
345*404b540aSrobert 	    for (size_t __k = _M_facets_size; __k < __new_size; ++__k)
346*404b540aSrobert 	      __newc[__k] = 0;
347*404b540aSrobert 
348*404b540aSrobert 	    _M_facets_size = __new_size;
349*404b540aSrobert 	    _M_facets = __newf;
350*404b540aSrobert 	    _M_caches = __newc;
351*404b540aSrobert 	    delete [] __oldf;
352*404b540aSrobert 	    delete [] __oldc;
353*404b540aSrobert 	  }
354*404b540aSrobert 
355*404b540aSrobert 	__fp->_M_add_reference();
356*404b540aSrobert 	const facet*& __fpr = _M_facets[__index];
357*404b540aSrobert 	if (__fpr)
358*404b540aSrobert 	  {
359*404b540aSrobert 	    // Replacing an existing facet. Order matters.
360*404b540aSrobert 	    __fpr->_M_remove_reference();
361*404b540aSrobert 	    __fpr = __fp;
362*404b540aSrobert 	  }
363*404b540aSrobert 	else
364*404b540aSrobert 	  {
365*404b540aSrobert 	    // Installing a newly created facet into an empty
366*404b540aSrobert 	    // _M_facets container, say a newly-constructed,
367*404b540aSrobert 	    // swanky-fresh _Impl.
368*404b540aSrobert 	    _M_facets[__index] = __fp;
369*404b540aSrobert 	  }
370*404b540aSrobert 
371*404b540aSrobert 	// Ideally, it would be nice to only remove the caches that
372*404b540aSrobert 	// are now incorrect. However, some of the caches depend on
373*404b540aSrobert 	// multiple facets, and we only know about one facet
374*404b540aSrobert 	// here. It's no great loss: the first use of the new facet
375*404b540aSrobert 	// will create a new, correctly cached facet anyway.
376*404b540aSrobert 	for (size_t __i = 0; __i < _M_facets_size; ++__i)
377*404b540aSrobert 	  {
378*404b540aSrobert 	    const facet* __cpr = _M_caches[__i];
379*404b540aSrobert 	    if (__cpr)
380*404b540aSrobert 	      {
381*404b540aSrobert 		__cpr->_M_remove_reference();
382*404b540aSrobert 		_M_caches[__i] = 0;
383*404b540aSrobert 	      }
384*404b540aSrobert 	  }
385*404b540aSrobert       }
386*404b540aSrobert   }
387*404b540aSrobert 
388*404b540aSrobert   void
389*404b540aSrobert   locale::_Impl::
_M_install_cache(const facet * __cache,size_t __index)390*404b540aSrobert   _M_install_cache(const facet* __cache, size_t __index)
391*404b540aSrobert   {
392*404b540aSrobert     __gnu_cxx::__scoped_lock sentry(locale_cache_mutex);
393*404b540aSrobert     if (_M_caches[__index] != 0)
394*404b540aSrobert       {
395*404b540aSrobert 	// Some other thread got in first.
396*404b540aSrobert 	delete __cache;
397*404b540aSrobert       }
398*404b540aSrobert     else
399*404b540aSrobert       {
400*404b540aSrobert 	__cache->_M_add_reference();
401*404b540aSrobert 	_M_caches[__index] = __cache;
402*404b540aSrobert       }
403*404b540aSrobert   }
404*404b540aSrobert 
405*404b540aSrobert   // locale::id
406*404b540aSrobert   // Definitions for static const data members of locale::id
407*404b540aSrobert   _Atomic_word locale::id::_S_refcount;  // init'd to 0 by linker
408*404b540aSrobert 
409*404b540aSrobert   size_t
_M_id() const410*404b540aSrobert   locale::id::_M_id() const
411*404b540aSrobert   {
412*404b540aSrobert     if (!_M_index)
413*404b540aSrobert       {
414*404b540aSrobert 	// XXX GLIBCXX_ABI Deprecated
415*404b540aSrobert #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
416*404b540aSrobert 	locale::id *f = 0;
417*404b540aSrobert # define _GLIBCXX_SYNC_ID(facet, mangled) \
418*404b540aSrobert 	if (this == &::mangled)				\
419*404b540aSrobert 	  f = &facet::id
420*404b540aSrobert 	_GLIBCXX_SYNC_ID (num_get<char>, _ZNSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
421*404b540aSrobert 	_GLIBCXX_SYNC_ID (num_put<char>, _ZNSt7num_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
422*404b540aSrobert 	_GLIBCXX_SYNC_ID (money_get<char>, _ZNSt9money_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE2idE);
423*404b540aSrobert 	_GLIBCXX_SYNC_ID (money_put<char>, _ZNSt9money_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE2idE);
424*404b540aSrobert # ifdef _GLIBCXX_USE_WCHAR_T
425*404b540aSrobert 	_GLIBCXX_SYNC_ID (num_get<wchar_t>, _ZNSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
426*404b540aSrobert 	_GLIBCXX_SYNC_ID (num_put<wchar_t>, _ZNSt7num_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
427*404b540aSrobert 	_GLIBCXX_SYNC_ID (money_get<wchar_t>, _ZNSt9money_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE2idE);
428*404b540aSrobert 	_GLIBCXX_SYNC_ID (money_put<wchar_t>, _ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE2idE);
429*404b540aSrobert # endif
430*404b540aSrobert 	if (f)
431*404b540aSrobert 	  _M_index = 1 + f->_M_id();
432*404b540aSrobert 	else
433*404b540aSrobert #endif
434*404b540aSrobert 	  _M_index = 1 + __gnu_cxx::__exchange_and_add_dispatch(&_S_refcount,
435*404b540aSrobert 								1);
436*404b540aSrobert       }
437*404b540aSrobert     return _M_index - 1;
438*404b540aSrobert   }
439*404b540aSrobert 
440*404b540aSrobert _GLIBCXX_END_NAMESPACE
441