re PR libstdc++/14071 (locale::global doesn't always call setlocale)

2004-02-09  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/14071
	* src/locale_init.cc (locale::global(const locale&)): Use
	locale::name() in order to decide whether calling setlocale.
	* testsuite/22_locale/locale/global_locale_objects/14071.cc: New.

	* include/bits/locale_classes.h (locale::_Impl::_M_check_same_name()):
	Avoid computing &= unnecessarily.

From-SVN: r77568
This commit is contained in:
Paolo Carlini 2004-02-09 23:10:47 +00:00 committed by Paolo Carlini
parent cee63f4d4e
commit cf0d2c4044
4 changed files with 62 additions and 4 deletions

View File

@ -1,3 +1,13 @@
2004-02-09 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/14071
* src/locale_init.cc (locale::global(const locale&)): Use
locale::name() in order to decide whether calling setlocale.
* testsuite/22_locale/locale/global_locale_objects/14071.cc: New.
* include/bits/locale_classes.h (locale::_Impl::_M_check_same_name()):
Avoid computing &= unnecessarily.
2004-02-09 James E Wilson <wilson@specifixinc.com>
PR libstdc++/5625

View File

@ -1,6 +1,6 @@
// Locale support -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -535,7 +535,7 @@ namespace std
{
bool __ret = true;
for (size_t __i = 0; __ret && __i < _S_categories_size - 1; ++__i)
__ret &= (std::strcmp(_M_names[__i], _M_names[__i + 1]) == 0);
__ret = std::strcmp(_M_names[__i], _M_names[__i + 1]) == 0;
return __ret;
}

View File

@ -108,8 +108,7 @@ namespace std
_Impl* __old = _S_global;
__other._M_impl->_M_add_reference();
_S_global = __other._M_impl;
if (_S_global->_M_check_same_name()
&& (std::strcmp(_S_global->_M_names[0], "*") != 0))
if (__other.name() != "*")
setlocale(LC_ALL, __other.name().c_str());
// Reference count sanity check: one reference removed for the

View File

@ -0,0 +1,49 @@
// 2004-02-09 Petur Runolfsson <peturr02@ru.is>
// Copyright (C) 2004 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 22.1.1.5 locale static members [lib.locale.statics]
#include <locale>
#include <clocale>
#include <testsuite_hooks.h>
// libstdc++/14071
void test01()
{
using namespace std;
bool test __attribute__((unused)) = true;
const locale loc_is = __gnu_test::try_named_locale("is_IS");
const locale loc_en = __gnu_test::try_named_locale("en_US");
const locale loc(loc_is, loc_en, locale::monetary);
if (loc.name() != "*")
{
locale::global(loc);
VERIFY( loc.name() == setlocale(LC_ALL, NULL) );
}
}
int main()
{
test01();
return 0;
}