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++/13007


Hi,

tested x86-linux, committed.

Paolo.

/////////
2003-11-13  Paolo Carlini  <pcarlini@suse.de>
	    Petur Runolfsson  <peturr02@ru.is>

	PR libstdc++/13007
	* include/bits/fstream.tcc (imbue): Don't touch the stored
	locale.
	* include/std/std_streambuf.h (imbue): According to the
	standard, base class version does nothing.
	(pubimbue): Store the locale.
	* testsuite/27_io/basic_filebuf/imbue/char/13007.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc: New.
	* testsuite/27_io/basic_filebuf/imbue/char/2.cc: Tweak.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc: New.
	* testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc: New.
	* testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc: New.
	* testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc: New.
diff -urN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
--- libstdc++-v3-orig/include/bits/fstream.tcc	2003-11-12 01:47:49.000000000 +0100
+++ libstdc++-v3/include/bits/fstream.tcc	2003-11-12 10:46:24.000000000 +0100
@@ -742,7 +742,7 @@
     basic_filebuf<_CharT, _Traits>::
     imbue(const locale& __loc)
     {
-      if (this->_M_buf_locale != __loc)
+      if (this->getloc() != __loc)
 	{
 	  bool __testfail = false;
 	  if (this->is_open())
@@ -758,7 +758,6 @@
 
 	  if (!__testfail)
 	    {
-	      this->_M_buf_locale = __loc;
 	      if (__builtin_expect(has_facet<__codecvt_type>(__loc), true))
 		_M_codecvt = &use_facet<__codecvt_type>(__loc);
 	      else
diff -urN libstdc++-v3-orig/include/std/std_streambuf.h libstdc++-v3/include/std/std_streambuf.h
--- libstdc++-v3-orig/include/std/std_streambuf.h	2003-10-12 12:12:08.000000000 +0200
+++ libstdc++-v3/include/std/std_streambuf.h	2003-11-12 10:47:05.000000000 +0100
@@ -200,6 +200,7 @@
       {
 	locale __tmp(this->getloc());
 	this->imbue(__loc);
+	_M_buf_locale = __loc;
 	return __tmp;
       }
 
@@ -538,15 +539,13 @@
        *  are changed by this call.  The standard adds, "Between invocations
        *  of this function a class derived from streambuf can safely cache
        *  results of calls to locale functions and to members of facets
-       *  so obtained."  This function simply stores the new locale for use
-       *  by derived classes.
+       *  so obtained."
+       *
+       *  @note  Base class version does nothing.
       */
       virtual void 
-      imbue(const locale& __loc) 
-      { 
-	if (_M_buf_locale != __loc)
-	  _M_buf_locale = __loc;
-      }
+      imbue(const locale&) 
+      { }
 
       // [27.5.2.4.2] buffer management and positioning
       /**
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/imbue/char/13007.cc libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_filebuf/imbue/char/13007.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc	2003-11-12 10:46:24.000000000 +0100
@@ -0,0 +1,61 @@
+// Copyright (C) 2003 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
+// 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.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf : public std::filebuf
+{
+public:
+  std::locale before;
+  std::locale after;
+
+protected:
+  void imbue(const std::locale& loc)
+  {
+    before = getloc();
+
+    std::filebuf::imbue(loc);
+
+    after = getloc();
+  }
+};
+
+// libstdc++/13007
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  Buf buf;
+  std::locale loc(__gnu_test::try_named_locale("fr_FR"));
+
+  buf.pubimbue(loc);
+
+  VERIFY( buf.getloc() == loc );
+  VERIFY( buf.before == std::locale::classic() );
+  VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/imbue/char/2.cc libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_filebuf/imbue/char/2.cc	2003-09-23 22:02:54.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc	2003-11-12 10:46:24.000000000 +0100
@@ -41,10 +41,12 @@
   pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
   VERIFY( p != bad);
 
-  // 1 "if file is not positioned at its beginning" fails...
+  // "if file is not positioned at its beginning" imbue fails
+  // but, according to 27.5.2.2.1, p1, still loc == getloc()
+  // after pubimbue(loc).
   locale loc_de = __gnu_test::try_named_locale("de_DE");
   locale ret = ob.pubimbue(loc_de);
-  VERIFY( ob.getloc() == loc );
+  VERIFY( ob.getloc() == loc_de );
 }
 
 int main() 
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc	2003-11-12 10:46:24.000000000 +0100
@@ -0,0 +1,61 @@
+// Copyright (C) 2003 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
+// 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.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf : public std::wfilebuf
+{
+public:
+  std::locale before;
+  std::locale after;
+
+protected:
+  void imbue(const std::locale& loc)
+  {
+    before = getloc();
+
+    std::wfilebuf::imbue(loc);
+
+    after = getloc();
+  }
+};
+
+// libstdc++/13007
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  Buf buf;
+  std::locale loc(__gnu_test::try_named_locale("fr_FR"));
+
+  buf.pubimbue(loc);
+
+  VERIFY( buf.getloc() == loc );
+  VERIFY( buf.before == std::locale::classic() );
+  VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc	2003-09-23 22:02:54.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc	2003-11-12 10:46:24.000000000 +0100
@@ -41,10 +41,12 @@
   pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
   VERIFY( p != bad);
 
-  // 1 "if file is not positioned at its beginning" fails...
+  // "if file is not positioned at its beginning" imbue fails
+  // but, according to 27.5.2.2.1, p1, still loc == getloc()
+  // after pubimbue(loc).
   locale loc_de = __gnu_test::try_named_locale("de_DE");
   locale ret = ob.pubimbue(loc_de);
-  VERIFY( ob.getloc() == loc );
+  VERIFY( ob.getloc() == loc_de );
 }
 
 int main() 
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc	2003-11-12 10:46:24.000000000 +0100
@@ -0,0 +1,49 @@
+// Copyright (C) 2003 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
+// 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.
+
+// 27.5.2.4.1 Locales
+
+#include <streambuf>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf1 : public std::streambuf
+{
+protected:
+  void imbue(const std::locale&)
+  { }
+};
+
+// libstdc++/13007
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  
+  Buf1 buf;
+  std::locale loc(__gnu_test::try_named_locale("is_IS.UTF-8"));
+
+  buf.pubimbue(loc);
+
+  VERIFY( buf.getloc() == loc );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc	2003-11-12 10:46:24.000000000 +0100
@@ -0,0 +1,61 @@
+// Copyright (C) 2003 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
+// 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.
+
+// 27.5.2.4.1 Locales
+
+#include <streambuf>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf2 : public std::streambuf
+{
+public:
+  std::locale before;
+  std::locale after;
+
+protected:
+  void imbue(const std::locale& loc)
+  {
+    before = getloc();
+
+    std::streambuf::imbue(loc);
+
+    after = getloc();
+  }
+};
+
+// libstdc++/13007
+void test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  Buf2 buf;
+  std::locale loc(__gnu_test::try_named_locale("en_US"));
+
+  buf.pubimbue(loc);
+
+  VERIFY( buf.getloc() == loc );
+  VERIFY( buf.before == std::locale::classic() );
+  VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc	2003-11-12 10:46:24.000000000 +0100
@@ -0,0 +1,49 @@
+// Copyright (C) 2003 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
+// 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.
+
+// 27.5.2.4.1 Locales
+
+#include <streambuf>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf1 : public std::wstreambuf
+{
+protected:
+  void imbue(const std::locale&)
+  { }
+};
+
+// libstdc++/13007
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  
+  Buf1 buf;
+  std::locale loc(__gnu_test::try_named_locale("is_IS.UTF-8"));
+
+  buf.pubimbue(loc);
+
+  VERIFY( buf.getloc() == loc );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc	2003-11-12 10:46:24.000000000 +0100
@@ -0,0 +1,61 @@
+// Copyright (C) 2003 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
+// 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.
+
+// 27.5.2.4.1 Locales
+
+#include <streambuf>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf2 : public std::wstreambuf
+{
+public:
+  std::locale before;
+  std::locale after;
+
+protected:
+  void imbue(const std::locale& loc)
+  {
+    before = getloc();
+
+    std::wstreambuf::imbue(loc);
+
+    after = getloc();
+  }
+};
+
+// libstdc++/13007
+void test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  Buf2 buf;
+  std::locale loc(__gnu_test::try_named_locale("en_US"));
+
+  buf.pubimbue(loc);
+
+  VERIFY( buf.getloc() == loc );
+  VERIFY( buf.before == std::locale::classic() );
+  VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}

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