This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch] Fix libstdc++/15565


Hi,

the below is what I propose to fix this rather subtle corner case.
I don't think we can do much better within the current ABI: otherwise,
perhaps, changing the __neg parameter of the __int_to_char template to
tri-state (i.e., positive, negative, and unsigned) could lead to a
cleaner solution.

I will wait until tomorrow. If everything goes well during the next
days, should be sufficiently safe for 3.4.1 too.

Paolo.

///////////
2004-05-22  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/15565
	* include/bits/locale_facets.tcc (__int_to_char(unsigned long),
	(__int_to_char(unsigned long long)): Showpos is not relevant
	for unsigned types.
	* testsuite/22_locale/num_put/put/char/15565.cc: New.
	* testsuite/22_locale/num_put/put/wchar_t/15565.cc: New.

	* testsuite/22_locale/num_put/put/wchar_t/1.cc: Use L for the fill
	char.
	* testsuite/22_locale/num_put/put/wchar_t/2.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/3.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/4.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/5.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/6.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/8.cc: Likewise.
diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc	2004-03-24 07:41:06.000000000 +0100
+++ libstdc++-v3/include/bits/locale_facets.tcc	2004-05-21 21:23:39.000000000 +0200
@@ -497,7 +497,8 @@
 
 	// At this point, base is determined. If not hex, only allow
 	// base digits as valid input.
-	const size_t __len = __base == 16 ? __num_base::_S_iend - __num_base::_S_izero : __base;
+	const size_t __len = (__base == 16 ? __num_base::_S_iend
+			      - __num_base::_S_izero : __base);
 
 	// Extract.
 	string __found_grouping;
@@ -826,7 +827,11 @@
     inline int
     __int_to_char(_CharT* __bufend, unsigned long __v, const _CharT* __lit,
 		  ios_base::fmtflags __flags)
-    { return __int_to_char(__bufend, __v, __lit, __flags, false); }
+    {
+      // About showpos, see Table 60 and C99 7.19.6.1, p6 (+).
+      return __int_to_char(__bufend, __v, __lit,
+			   __flags & ~ios_base::showpos, false);
+    }
 
 #ifdef _GLIBCXX_USE_LONG_LONG
   template<typename _CharT>
@@ -848,7 +853,8 @@
     inline int
     __int_to_char(_CharT* __bufend, unsigned long long __v, 
 		  const _CharT* __lit, ios_base::fmtflags __flags)
-    { return __int_to_char(__bufend, __v, __lit, __flags, false); }
+    { return __int_to_char(__bufend, __v, __lit,
+			   __flags & ~ios_base::showpos, false); }
 #endif
 
   template<typename _CharT, typename _ValueT>
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/char/15565.cc libstdc++-v3/testsuite/22_locale/num_put/put/char/15565.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/char/15565.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/num_put/put/char/15565.cc	2004-05-21 20:47:10.000000000 +0200
@@ -0,0 +1,63 @@
+// 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.2.2.2.1  num_put members
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/15565
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  // basic construction
+  locale loc_c = locale::classic();
+
+  // sanity check the data is correct.
+  const string empty;
+
+  // cache the num_put facet
+  ostringstream oss;
+  oss.imbue(loc_c);
+  const num_put<char>& np = use_facet<num_put<char> >(oss.getloc());
+
+  unsigned long ul1 = 42UL;
+  oss.str(empty);
+  oss.clear();
+  oss.setf(ios_base::showpos);
+  np.put(oss.rdbuf(), oss, ' ', ul1);
+  VERIFY( oss.str() == "42" );
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+  unsigned long long ull1 = 31ULL;
+  oss.str(empty);
+  oss.clear();
+  oss.setf(ios_base::showpos);
+  np.put(oss.rdbuf(), oss, ' ', ull1);
+  VERIFY( oss.str() == "31" );
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/1.cc libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/1.cc	2004-04-09 12:18:32.000000000 +0200
+++ libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc	2004-05-21 20:40:59.000000000 +0200
@@ -60,13 +60,13 @@
 
   // bool, simple
   iterator_type os_it00 = oss.rdbuf();
-  iterator_type os_it01 = np.put(os_it00, oss, '+', b1);
+  iterator_type os_it01 = np.put(os_it00, oss, L'+', b1);
   result1 = oss.str();
   VERIFY( result1 == L"1" );
   //  VERIFY( os_it00 != os_it01 );
 
   oss.str(empty);
-  np.put(oss.rdbuf(), oss, '+', b0);
+  np.put(oss.rdbuf(), oss, L'+', b0);
   result2 = oss.str();
   VERIFY( result2 == L"0" );
 
@@ -76,7 +76,7 @@
   oss.clear();
   oss.width(20);
   oss.setf(ios_base::left, ios_base::adjustfield);
-  np.put(oss.rdbuf(), oss, '+', ul1);
+  np.put(oss.rdbuf(), oss, L'+', ul1);
   result1 = oss.str();
   VERIFY( result1 == L"1.294.967.294+++++++" );
 
@@ -85,7 +85,7 @@
   oss.clear();
   oss.width(20);
   oss.setf(ios_base::left, ios_base::adjustfield);
-  np.put(oss.rdbuf(), oss, '+', d1);
+  np.put(oss.rdbuf(), oss, L'+', d1);
   result1 = oss.str();
   VERIFY( result1 == L"1,79769e+308++++++++" );
 
@@ -93,7 +93,7 @@
   oss.clear();
   oss.width(20);
   oss.setf(ios_base::right, ios_base::adjustfield);
-  np.put(oss.rdbuf(), oss, '+', d2);
+  np.put(oss.rdbuf(), oss, L'+', d2);
   result1 = oss.str();
   VERIFY( result1 == L"++++++++2,22507e-308" );
 
@@ -102,7 +102,7 @@
   oss.width(20);
   oss.setf(ios_base::right, ios_base::adjustfield);
   oss.setf(ios_base::scientific, ios_base::floatfield);
-  np.put(oss.rdbuf(), oss, '+', d2);
+  np.put(oss.rdbuf(), oss, L'+', d2);
   result2 = oss.str();
   VERIFY( result2 == L"+++++++2,225074e-308" );
 
@@ -113,14 +113,14 @@
   oss.setf(ios_base::right, ios_base::adjustfield);
   oss.setf(ios_base::scientific, ios_base::floatfield);
   oss.setf(ios_base::uppercase);
-  np.put(oss.rdbuf(), oss, '+', d2);
+  np.put(oss.rdbuf(), oss, L'+', d2);
   result1 = oss.str();
   VERIFY( result1 == L"+++2,2250738585E-308" );
 
   // long double
   oss.str(empty);
   oss.clear();
-  np.put(oss.rdbuf(), oss, '+', ld1);
+  np.put(oss.rdbuf(), oss, L'+', ld1);
   result1 = oss.str();
   VERIFY( result1 == L"1,7976931349E+308" );
 
@@ -128,14 +128,14 @@
   oss.clear();
   oss.precision(0);
   oss.setf(ios_base::fixed, ios_base::floatfield);
-  np.put(oss.rdbuf(), oss, '+', ld2);
+  np.put(oss.rdbuf(), oss, L'+', ld2);
   result1 = oss.str();
   VERIFY( result1 == L"0" );
 
   // const void
   oss.str(empty);
   oss.clear();
-  np.put(oss.rdbuf(), oss, '+', cv);
+  np.put(oss.rdbuf(), oss, L'+', cv);
   result1 = oss.str();
   // No grouping characters.
   VERIFY( !char_traits<wchar_t>::find(result1.c_str(), 
@@ -149,7 +149,7 @@
 
   oss.str(empty);
   oss.clear();
-  np.put(oss.rdbuf(), oss, '+', ll1);
+  np.put(oss.rdbuf(), oss, L'+', ll1);
   result1 = oss.str();
   VERIFY( result1 == L"9.223.372.036.854.775.807" );
 #endif
@@ -160,5 +160,3 @@
   test01();
   return 0;
 }
-
-
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/15565.cc libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/15565.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/15565.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/15565.cc	2004-05-21 20:39:28.000000000 +0200
@@ -0,0 +1,63 @@
+// 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.2.2.2.1  num_put members
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/15565
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  // basic construction
+  locale loc_c = locale::classic();
+
+  // sanity check the data is correct.
+  const wstring empty;
+
+  // cache the num_put facet
+  wostringstream oss;
+  oss.imbue(loc_c);
+  const num_put<wchar_t>& np = use_facet<num_put<wchar_t> >(oss.getloc());
+
+  unsigned long ul1 = 42UL;
+  oss.str(empty);
+  oss.clear();
+  oss.setf(ios_base::showpos);
+  np.put(oss.rdbuf(), oss, L' ', ul1);
+  VERIFY( oss.str() == L"42" );
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+  unsigned long long ull1 = 31ULL;
+  oss.str(empty);
+  oss.clear();
+  oss.setf(ios_base::showpos);
+  np.put(oss.rdbuf(), oss, L' ', ull1);
+  VERIFY( oss.str() == L"31" );
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/2.cc libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/2.cc	2004-04-09 12:18:32.000000000 +0200
+++ libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc	2004-05-21 20:41:23.000000000 +0200
@@ -54,7 +54,7 @@
   oss.str(empty);
   oss.width(20);
   oss.setf(ios_base::right, ios_base::adjustfield);
-  np.put(oss.rdbuf(), oss, '+', b0);
+  np.put(oss.rdbuf(), oss, L'+', b0);
   result1 = oss.str();
   VERIFY( result1 == L"+++++++++++++++++++0" );
 
@@ -62,7 +62,7 @@
   oss.width(20);
   oss.setf(ios_base::left, ios_base::adjustfield);
   oss.setf(ios_base::boolalpha);
-  np.put(oss.rdbuf(), oss, '+', b1);
+  np.put(oss.rdbuf(), oss, L'+', b1);
   result2 = oss.str();
   VERIFY( result2 == L"true++++++++++++++++" );
 
@@ -70,7 +70,7 @@
   oss.imbue(loc_c);
   oss.str(empty);
   oss.clear();
-  np.put(oss.rdbuf(), oss, '+', ul1);
+  np.put(oss.rdbuf(), oss, L'+', ul1);
   result1 = oss.str();
   VERIFY( result1 == L"1294967294" );
 
@@ -78,7 +78,7 @@
   oss.clear();
   oss.width(20);
   oss.setf(ios_base::left, ios_base::adjustfield);
-  np.put(oss.rdbuf(), oss, '+', ul2);
+  np.put(oss.rdbuf(), oss, L'+', ul2);
   result1 = oss.str();
   VERIFY( result1 == L"0+++++++++++++++++++" );
 }
@@ -88,5 +88,3 @@
   test02();
   return 0;
 }
-
-
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/3.cc libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/3.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/3.cc	2004-04-09 12:18:32.000000000 +0200
+++ libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/3.cc	2004-05-21 20:41:39.000000000 +0200
@@ -53,7 +53,7 @@
   // long, in a locale that expects grouping
   oss.str(empty);
   oss.clear();
-  np.put(oss.rdbuf(), oss, '+', l1);
+  np.put(oss.rdbuf(), oss, L'+', l1);
   result1 = oss.str();
   VERIFY( result1 == L"2,147,483,647" );
 
@@ -61,7 +61,7 @@
   oss.clear();
   oss.width(20);
   oss.setf(ios_base::left, ios_base::adjustfield);
-  np.put(oss.rdbuf(), oss, '+', l2);
+  np.put(oss.rdbuf(), oss, L'+', l2);
   result1 = oss.str();
   VERIFY( result1 == L"-2,147,483,647++++++" );
 }
@@ -71,5 +71,3 @@
   test03();
   return 0;
 }
-
-
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/4.cc libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/4.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/4.cc	2004-03-17 09:22:38.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/4.cc	2004-05-21 20:42:03.000000000 +0200
@@ -53,7 +53,7 @@
   // 01 put(long)
   const long l = 1798;
   res = x;
-  iter_type ret1 = tp.put(res.begin(), oss, ' ', l);
+  iter_type ret1 = tp.put(res.begin(), oss, L' ', l);
   wstring sanity1(res.begin(), ret1);
   VERIFY( res == L"1798xxxxxxxxxxxxxx" );
   VERIFY( sanity1 == L"1798" );
@@ -61,7 +61,7 @@
   // 02 put(long double)
   const long double ld = 1798.0;
   res = x;
-  iter_type ret2 = tp.put(res.begin(), oss, ' ', ld);
+  iter_type ret2 = tp.put(res.begin(), oss, L' ', ld);
   wstring sanity2(res.begin(), ret2);
   VERIFY( res == L"1798xxxxxxxxxxxxxx" );
   VERIFY( sanity2 == L"1798" );
@@ -69,7 +69,7 @@
   // 03 put(bool)
   bool b = 1;
   res = x;
-  iter_type ret3 = tp.put(res.begin(), oss, ' ', b);
+  iter_type ret3 = tp.put(res.begin(), oss, L' ', b);
   wstring sanity3(res.begin(), ret3);
   VERIFY( res == L"1xxxxxxxxxxxxxxxxx" );
   VERIFY( sanity3 == L"1" );
@@ -77,7 +77,7 @@
   b = 0;
   res = x;
   oss.setf(ios_base::boolalpha);
-  iter_type ret4 = tp.put(res.begin(), oss, ' ', b);
+  iter_type ret4 = tp.put(res.begin(), oss, L' ', b);
   wstring sanity4(res.begin(), ret4);
   VERIFY( res == L"falsexxxxxxxxxxxxx" );
   VERIFY( sanity4 == L"false" );
@@ -87,7 +87,7 @@
   const void* cv = &ld;
   res = x;
   oss.setf(ios_base::fixed, ios_base::floatfield);
-  iter_type ret5 = tp.put(res.begin(), oss, ' ', cv);
+  iter_type ret5 = tp.put(res.begin(), oss, L' ', cv);
   wstring sanity5(res.begin(), ret5);
   VERIFY( sanity5.size() );
   VERIFY( sanity5[1] == L'x' );
@@ -98,5 +98,3 @@
   test04();
   return 0;
 }
-
-
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/5.cc libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/5.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/5.cc	2003-09-23 22:02:32.000000000 +0200
+++ libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/5.cc	2004-05-21 20:42:21.000000000 +0200
@@ -48,7 +48,7 @@
   oss.clear();
   oss.setf(ios::showbase);
   oss.setf(ios::hex, ios::basefield);
-  np.put(oss.rdbuf(), oss, '+', l);
+  np.put(oss.rdbuf(), oss, L'+', l);
   result = oss.str();
   VERIFY( result == L"0" );
 
@@ -56,7 +56,7 @@
   oss.clear();
   oss.setf(ios::showbase);
   oss.setf(ios::oct, ios::basefield);
-  np.put(oss.rdbuf(), oss, '+', l);
+  np.put(oss.rdbuf(), oss, L'+', l);
   result = oss.str();
   VERIFY( result == L"0" );
 }
@@ -66,5 +66,3 @@
   test05();
   return 0;
 }
-
-
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/6.cc libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/6.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/6.cc	2003-09-23 22:02:32.000000000 +0200
+++ libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/6.cc	2004-05-21 20:42:41.000000000 +0200
@@ -38,13 +38,13 @@
 
   woss1.precision(-1);
   woss1.setf(ios_base::fixed, ios_base::floatfield);
-  np1.put(woss1.rdbuf(), woss1, '+', 30.5);
+  np1.put(woss1.rdbuf(), woss1, L'+', 30.5);
   result1 = woss1.str();
   VERIFY( result1 == L"30.500000" );
 
   woss2.precision(0);
   woss2.setf(ios_base::scientific, ios_base::floatfield);
-  np2.put(woss2.rdbuf(), woss2, '+', 1.0);
+  np2.put(woss2.rdbuf(), woss2, L'+', 1.0);
   result2 = woss2.str();
   VERIFY( result2 == L"1e+00" );
 }
diff -urN libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/8.cc libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/8.cc
--- libstdc++-v3-orig/testsuite/22_locale/num_put/put/wchar_t/8.cc	2003-11-17 09:39:57.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/8.cc	2004-05-21 20:43:00.000000000 +0200
@@ -51,13 +51,13 @@
   long inum = 123;
   double fnum = 123.456;
 
-  np.put(oss.rdbuf(), oss, '+', inum);
+  np.put(oss.rdbuf(), oss, L'+', inum);
   result = oss.str();
   VERIFY( result == L"XYZ" );
 
   oss.clear();
   oss.str(empty);
-  np.put(oss.rdbuf(), oss, '+', fnum);
+  np.put(oss.rdbuf(), oss, L'+', fnum);
   result = oss.str();
   VERIFY( result == L"XYZ.ABC" );
 }

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