This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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++/14071


Hi,

this bug is basically due to code remnant of the old days
when we didn't have implemented the POSIX locale names:
strictly following the standard (22.1.1.5, p2) fixes it
in a very clean way.

Took the occasion to simplify a bit _M_check_same_name,
which was computing unnecessarily an &= (the same tiny
unefficiency that we had in __verify_grouping)

Tested x86-linux.

Paolo.

//////////////
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.
diff -urN libstdc++-v3-orig/include/bits/locale_classes.h libstdc++-v3/include/bits/locale_classes.h
--- libstdc++-v3-orig/include/bits/locale_classes.h	2004-02-08 16:34:15.000000000 +0100
+++ libstdc++-v3/include/bits/locale_classes.h	2004-02-09 22:22:23.000000000 +0100
@@ -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 @@
     {
       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 -urN libstdc++-v3-orig/src/locale_init.cc libstdc++-v3/src/locale_init.cc
--- libstdc++-v3-orig/src/locale_init.cc	2004-01-28 22:20:42.000000000 +0100
+++ libstdc++-v3/src/locale_init.cc	2004-02-09 22:00:14.000000000 +0100
@@ -108,8 +108,7 @@
     _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 -urN libstdc++-v3-orig/testsuite/22_locale/locale/global_locale_objects/14071.cc libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc
--- libstdc++-v3-orig/testsuite/22_locale/locale/global_locale_objects/14071.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/14071.cc	2004-02-09 22:46:36.000000000 +0100
@@ -0,0 +1,50 @@
+// 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 <iostream>
+#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;
+}

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