This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Fix libstdc++/38368


Hi,

tested x86_64-linux, committed to mainline.

Paolo.

////////////////////
2008-12-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/38368
	* config/locale/gnu/numeric_members.cc (numpunct<char>::
	_M_initialize_numpunct, numpunct<wchar_t>::_M_initialize_numpunct):
	Fix for THOUSANDS_SEP == '\0' consistently with "C" locale.
	* config/locale/gnu/monetary_members.cc (moneypunct<char, true>::
	_M_initialize_moneypunct, moneypunct<char, false>::
	_M_initialize_moneypunct, moneypunct<wchar_t, true>::
	_M_initialize_moneypunct, moneypunct<wchar_t, false>::
	_M_initialize_moneypunct): Fix for __MON_DECIMAL_POINT == '\0' or
	__MON_THOUSANDS_SEP == '\0' consistently with "C" locale.
	* testsuite/22_locale/locale/cons/38368.cc: New.
Index: testsuite/22_locale/locale/cons/38368.cc
===================================================================
*** testsuite/22_locale/locale/cons/38368.cc	(revision 0)
--- testsuite/22_locale/locale/cons/38368.cc	(revision 0)
***************
*** 0 ****
--- 1,54 ----
+ // { dg-require-namedlocale "" }
+ 
+ // Copyright (C) 2008 Free Software Foundation
+ //
+ // This file is part of the GNU ISO C++ Library.  This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ // USA.
+ 
+ // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
+ 
+ #include <locale>
+ #include <testsuite_hooks.h>
+ 
+ // libstdc++/38368
+ void test01()
+ {
+   using namespace std;
+   bool test __attribute__((unused)) = true;
+ 
+   locale loc(locale("C"), "en_US", locale::collate);
+   locale loc_copy(loc.name().c_str());
+ 
+   const moneypunct<char, true>& mpunt =
+     use_facet<moneypunct<char, true> >(loc_copy);
+   VERIFY( mpunt.decimal_point() == '.' );
+   VERIFY( mpunt.thousands_sep() == ',' );
+ 
+   const moneypunct<char, false>& mpunf =
+     use_facet<moneypunct<char, false> >(loc_copy);
+   VERIFY( mpunf.decimal_point() == '.' );
+   VERIFY( mpunf.thousands_sep() == ',' );
+ 
+   const numpunct<char>& npun = use_facet<numpunct<char> >(loc_copy);
+   VERIFY( npun.decimal_point() == '.' );
+   VERIFY( npun.thousands_sep() == ',' );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
Index: config/locale/gnu/numeric_members.cc
===================================================================
*** config/locale/gnu/numeric_members.cc	(revision 142436)
--- config/locale/gnu/numeric_members.cc	(working copy)
***************
*** 1,6 ****
  // std::numpunct implementation details, GNU version -*- C++ -*-
  
! // Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
--- 1,7 ----
  // std::numpunct implementation details, GNU version -*- C++ -*-
  
! // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
! // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 71,80 ****
  
  	  // Check for NULL, which implies no grouping.
  	  if (_M_data->_M_thousands_sep == '\0')
! 	    _M_data->_M_grouping = "";
  	  else
! 	    _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc);
! 	  _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
  	}
  
        // NB: There is no way to extact this info from posix locales.
--- 72,89 ----
  
  	  // Check for NULL, which implies no grouping.
  	  if (_M_data->_M_thousands_sep == '\0')
! 	    {
! 	      // Like in "C" locale.
! 	      _M_data->_M_grouping = "";
! 	      _M_data->_M_grouping_size = 0;
! 	      _M_data->_M_use_grouping = false;
! 	      _M_data->_M_thousands_sep = ',';
! 	    }
  	  else
! 	    {
! 	      _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc);
! 	      _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
! 	    }
  	}
  
        // NB: There is no way to extact this info from posix locales.
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 128,138 ****
  	  __u.__s = __nl_langinfo_l(_NL_NUMERIC_THOUSANDS_SEP_WC, __cloc);
  	  _M_data->_M_thousands_sep = __u.__w;
  
  	  if (_M_data->_M_thousands_sep == L'\0')
! 	    _M_data->_M_grouping = "";
  	  else
! 	    _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc);
! 	  _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
  	}
  
        // NB: There is no way to extact this info from posix locales.
--- 137,156 ----
  	  __u.__s = __nl_langinfo_l(_NL_NUMERIC_THOUSANDS_SEP_WC, __cloc);
  	  _M_data->_M_thousands_sep = __u.__w;
  
+ 	  // Check for NULL, which implies no grouping.
  	  if (_M_data->_M_thousands_sep == L'\0')
! 	    {
! 	      // Like in "C" locale.
! 	      _M_data->_M_grouping = "";
! 	      _M_data->_M_grouping_size = 0;
! 	      _M_data->_M_use_grouping = false;
! 	      _M_data->_M_thousands_sep = L',';
! 	    }
  	  else
! 	    {
! 	      _M_data->_M_grouping = __nl_langinfo_l(GROUPING, __cloc);
! 	      _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
! 	    }
  	}
  
        // NB: There is no way to extact this info from posix locales.
Index: config/locale/gnu/monetary_members.cc
===================================================================
*** config/locale/gnu/monetary_members.cc	(revision 142436)
--- config/locale/gnu/monetary_members.cc	(working copy)
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 220,225 ****
--- 220,226 ----
  	  _M_data->_M_thousands_sep = ',';
  	  _M_data->_M_grouping = "";
  	  _M_data->_M_grouping_size = 0;
+ 	  _M_data->_M_use_grouping = false;
  	  _M_data->_M_curr_symbol = "";
  	  _M_data->_M_curr_symbol_size = 0;
  	  _M_data->_M_positive_sign = "";
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 240,250 ****
  							__cloc));
  	  _M_data->_M_thousands_sep = *(__nl_langinfo_l(__MON_THOUSANDS_SEP, 
  							__cloc));
- 	  _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
- 	  _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
  	  _M_data->_M_positive_sign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
  	  _M_data->_M_positive_sign_size = strlen(_M_data->_M_positive_sign);
  
  	  char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc));
  	  if (!__nposn)
  	    _M_data->_M_negative_sign = "()";
--- 241,275 ----
  							__cloc));
  	  _M_data->_M_thousands_sep = *(__nl_langinfo_l(__MON_THOUSANDS_SEP, 
  							__cloc));
  	  _M_data->_M_positive_sign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
  	  _M_data->_M_positive_sign_size = strlen(_M_data->_M_positive_sign);
  
+ 	  // Check for NULL, which implies no grouping.
+ 	  if (_M_data->_M_thousands_sep == '\0')
+ 	    {
+ 	      // Like in "C" locale.
+ 	      _M_data->_M_grouping = "";
+ 	      _M_data->_M_grouping_size = 0;
+ 	      _M_data->_M_use_grouping = false;
+ 	      _M_data->_M_thousands_sep = ',';
+ 	    }
+ 	  else
+ 	    {
+ 	      _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
+ 	      _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
+ 	    }
+ 
+ 	  // Check for NULL, which implies no fractional digits.
+ 	  if (_M_data->_M_decimal_point == '\0')
+ 	    {
+ 	      // Like in "C" locale.
+ 	      _M_data->_M_frac_digits = 0;
+ 	      _M_data->_M_decimal_point = '.';
+ 	    }
+ 	  else
+ 	    _M_data->_M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, 
+ 							__cloc));
+ 
  	  char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc));
  	  if (!__nposn)
  	    _M_data->_M_negative_sign = "()";
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 256,263 ****
  	  // _Intl == true
  	  _M_data->_M_curr_symbol = __nl_langinfo_l(__INT_CURR_SYMBOL, __cloc);
  	  _M_data->_M_curr_symbol_size = strlen(_M_data->_M_curr_symbol);
- 	  _M_data->_M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, 
- 						      __cloc));
  	  char __pprecedes = *(__nl_langinfo_l(__INT_P_CS_PRECEDES, __cloc));
  	  char __pspace = *(__nl_langinfo_l(__INT_P_SEP_BY_SPACE, __cloc));
  	  char __pposn = *(__nl_langinfo_l(__INT_P_SIGN_POSN, __cloc));
--- 281,286 ----
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 285,290 ****
--- 308,314 ----
  	  _M_data->_M_thousands_sep = ',';
  	  _M_data->_M_grouping = "";
  	  _M_data->_M_grouping_size = 0;
+ 	  _M_data->_M_use_grouping = false;
  	  _M_data->_M_curr_symbol = "";
  	  _M_data->_M_curr_symbol_size = 0;
  	  _M_data->_M_positive_sign = "";
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 305,315 ****
  							__cloc));
  	  _M_data->_M_thousands_sep = *(__nl_langinfo_l(__MON_THOUSANDS_SEP, 
  							__cloc));
- 	  _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
- 	  _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
  	  _M_data->_M_positive_sign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
  	  _M_data->_M_positive_sign_size = strlen(_M_data->_M_positive_sign);
  
  	  char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc));
  	  if (!__nposn)
  	    _M_data->_M_negative_sign = "()";
--- 329,363 ----
  							__cloc));
  	  _M_data->_M_thousands_sep = *(__nl_langinfo_l(__MON_THOUSANDS_SEP, 
  							__cloc));
  	  _M_data->_M_positive_sign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
  	  _M_data->_M_positive_sign_size = strlen(_M_data->_M_positive_sign);
  
+ 	  // Check for NULL, which implies no grouping.
+ 	  if (_M_data->_M_thousands_sep == '\0')
+ 	    {
+ 	      // Like in "C" locale.
+ 	      _M_data->_M_grouping = "";
+ 	      _M_data->_M_grouping_size = 0;
+ 	      _M_data->_M_use_grouping = false;
+ 	      _M_data->_M_thousands_sep = ',';
+ 	    }
+ 	  else
+ 	    {
+ 	      _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
+ 	      _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
+ 	    }
+ 
+ 	  // Check for NULL, which implies no fractional digits.
+ 	  if (_M_data->_M_decimal_point == '\0')
+ 	    {
+ 	      // Like in "C" locale.
+ 	      _M_data->_M_frac_digits = 0;
+ 	      _M_data->_M_decimal_point = '.';
+ 	    }
+ 	  else
+ 	    _M_data->_M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS,
+ 							__cloc));
+ 
  	  char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc));
  	  if (!__nposn)
  	    _M_data->_M_negative_sign = "()";
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 321,327 ****
  	  // _Intl == false
  	  _M_data->_M_curr_symbol = __nl_langinfo_l(__CURRENCY_SYMBOL, __cloc);
  	  _M_data->_M_curr_symbol_size = strlen(_M_data->_M_curr_symbol);
- 	  _M_data->_M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS, __cloc));
  	  char __pprecedes = *(__nl_langinfo_l(__P_CS_PRECEDES, __cloc));
  	  char __pspace = *(__nl_langinfo_l(__P_SEP_BY_SPACE, __cloc));
  	  char __pposn = *(__nl_langinfo_l(__P_SIGN_POSN, __cloc));
--- 369,374 ----
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 362,367 ****
--- 409,415 ----
  	  _M_data->_M_thousands_sep = L',';
  	  _M_data->_M_grouping = "";
  	  _M_data->_M_grouping_size = 0;
+ 	  _M_data->_M_use_grouping = false;
  	  _M_data->_M_curr_symbol = L"";
  	  _M_data->_M_curr_symbol_size = 0;
  	  _M_data->_M_positive_sign = L"";
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 397,404 ****
  
  	  __u.__s = __nl_langinfo_l(_NL_MONETARY_THOUSANDS_SEP_WC, __cloc);
  	  _M_data->_M_thousands_sep = __u.__w;
! 	  _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
! 	  _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
  
  	  const char* __cpossign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
  	  const char* __cnegsign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc);
--- 445,476 ----
  
  	  __u.__s = __nl_langinfo_l(_NL_MONETARY_THOUSANDS_SEP_WC, __cloc);
  	  _M_data->_M_thousands_sep = __u.__w;
! 
! 	  // Check for NULL, which implies no grouping.
! 	  if (_M_data->_M_thousands_sep == L'\0')
! 	    {
! 	      // Like in "C" locale.
! 	      _M_data->_M_grouping = "";
! 	      _M_data->_M_grouping_size = 0;
! 	      _M_data->_M_use_grouping = false;
! 	      _M_data->_M_thousands_sep = L',';
! 	    }
! 	  else
! 	    {
! 	      _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
! 	      _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
! 	    }
! 
! 	  // Check for NULL, which implies no fractional digits.
! 	  if (_M_data->_M_decimal_point == L'\0')
! 	    {
! 	      // Like in "C" locale.
! 	      _M_data->_M_frac_digits = 0;
! 	      _M_data->_M_decimal_point = L'.';
! 	    }
! 	  else
! 	    _M_data->_M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, 
! 							__cloc));
  
  	  const char* __cpossign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
  	  const char* __cnegsign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc);
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 467,474 ****
  	      __throw_exception_again;
  	    } 
  	  
- 	  _M_data->_M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, 
- 						      __cloc));
  	  char __pprecedes = *(__nl_langinfo_l(__INT_P_CS_PRECEDES, __cloc));
  	  char __pspace = *(__nl_langinfo_l(__INT_P_SEP_BY_SPACE, __cloc));
  	  char __pposn = *(__nl_langinfo_l(__INT_P_SIGN_POSN, __cloc));
--- 539,544 ----
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 507,512 ****
--- 577,583 ----
  	  _M_data->_M_thousands_sep = L',';
  	  _M_data->_M_grouping = "";
            _M_data->_M_grouping_size = 0;
+ 	  _M_data->_M_use_grouping = false;
  	  _M_data->_M_curr_symbol = L"";
  	  _M_data->_M_curr_symbol_size = 0;
  	  _M_data->_M_positive_sign = L"";
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 542,549 ****
  
  	  __u.__s = __nl_langinfo_l(_NL_MONETARY_THOUSANDS_SEP_WC, __cloc);
  	  _M_data->_M_thousands_sep = __u.__w;
! 	  _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
!           _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
  
  	  const char* __cpossign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
  	  const char* __cnegsign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc);
--- 613,644 ----
  
  	  __u.__s = __nl_langinfo_l(_NL_MONETARY_THOUSANDS_SEP_WC, __cloc);
  	  _M_data->_M_thousands_sep = __u.__w;
! 
! 	  // Check for NULL, which implies no grouping.
! 	  if (_M_data->_M_thousands_sep == L'\0')
! 	    {
! 	      // Like in "C" locale.
! 	      _M_data->_M_grouping = "";
! 	      _M_data->_M_grouping_size = 0;
! 	      _M_data->_M_use_grouping = false;
! 	      _M_data->_M_thousands_sep = L',';
! 	    }
! 	  else
! 	    {
! 	      _M_data->_M_grouping = __nl_langinfo_l(__MON_GROUPING, __cloc);
! 	      _M_data->_M_grouping_size = strlen(_M_data->_M_grouping);
! 	    }
! 
! 	  // Check for NULL, which implies no fractional digits.
! 	  if (_M_data->_M_decimal_point == L'\0')
! 	    {
! 	      // Like in "C" locale.
! 	      _M_data->_M_frac_digits = 0;
! 	      _M_data->_M_decimal_point = L'.';
! 	    }
! 	  else
! 	    _M_data->_M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS,
! 							__cloc));
  
  	  const char* __cpossign = __nl_langinfo_l(__POSITIVE_SIGN, __cloc);
  	  const char* __cnegsign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc);
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 613,619 ****
                __throw_exception_again;
  	    }
  
- 	  _M_data->_M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS, __cloc));
  	  char __pprecedes = *(__nl_langinfo_l(__P_CS_PRECEDES, __cloc));
  	  char __pspace = *(__nl_langinfo_l(__P_SEP_BY_SPACE, __cloc));
  	  char __pposn = *(__nl_langinfo_l(__P_SIGN_POSN, __cloc));
--- 708,713 ----

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]