diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e18aff6df8b..b519c948a26 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2004-02-09 Paolo Carlini + + 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 PR libstdc++/5625 diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h index 33eb47576db..e4f5c17780e 100644 --- a/libstdc++-v3/include/bits/locale_classes.h +++ b/libstdc++-v3/include/bits/locale_classes.h @@ -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; } diff --git a/libstdc++-v3/src/locale_init.cc b/libstdc++-v3/src/locale_init.cc index a00366bb066..276d6864191 100644 --- a/libstdc++-v3/src/locale_init.cc +++ b/libstdc++-v3/src/locale_init.cc @@ -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 diff --git a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc new file mode 100644 index 00000000000..7c143f4f577 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc @@ -0,0 +1,49 @@ +// 2004-02-09 Petur Runolfsson + +// 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 +#include +#include + +// 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; +}