]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/14071 (locale::global doesn't always call setlocale)
authorPaolo Carlini <pcarlini@suse.de>
Mon, 9 Feb 2004 23:10:47 +0000 (23:10 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 9 Feb 2004 23:10:47 +0000 (23:10 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_classes.h
libstdc++-v3/src/locale_init.cc
libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc [new file with mode: 0644]

index e18aff6df8b1863f7046042eaec8a39c3b12f968..b519c948a269861ccebb7e81cc4980dff70ac1db 100644 (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
index 33eb47576db69ef97b3d3ff4abe351a23b93c75c..e4f5c17780e33d3f2882adfacdad2f1ec4b11934 100644 (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;
     }
 
index a00366bb06690c5941070026a9c7f9708fe4ce4d..276d68641913302b7ffed1655dfaf54c62482950 100644 (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
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 (file)
index 0000000..7c143f4
--- /dev/null
@@ -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;
+}