OSDN Git Service

2005-07-11 Paolo Carlini <pcarlini@suse.de>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 11 Jul 2005 09:48:31 +0000 (09:48 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 11 Jul 2005 09:48:31 +0000 (09:48 +0000)
* include/bits/ostream.tcc (basic_ostream<>::operator<<(long),
basic_ostream<>::operator<<(long long)): Don't deal with oct
and hex and casts to unsigned here...
* include/bits/locale_facets.tcc (__int_to_char(_CharT*, long,
const _CharT*, ios_base::fmtflags), __int_to_char(_CharT*, long
long, const _CharT*, ios_base::fmtflags)): ... do that here,
instead, as per Table 57.
(num_put<>::_M_insert_int): Tidy treatment of numeric base and
sign.
* include/std/std_ostream.h (operator<<(short), operator<<(int)):
Adjust logic, as per the letter of the resolution of DR117 [WP].
* testsuite/22_locale/num_put/put/char/10.cc: New.
* testsuite/22_locale/num_put/put/wchar_t/10.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc:
Likewise.
* testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc:
Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101872 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.tcc
libstdc++-v3/include/bits/ostream.tcc
libstdc++-v3/include/std/std_ostream.h
libstdc++-v3/testsuite/22_locale/num_put/put/char/10.cc [new file with mode: 0644]
libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/10.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc [new file with mode: 0644]

index 6704abf..7ab1fca 100644 (file)
@@ -1,3 +1,23 @@
+2005-07-11  Paolo Carlini  <pcarlini@suse.de>
+
+       * include/bits/ostream.tcc (basic_ostream<>::operator<<(long),
+       basic_ostream<>::operator<<(long long)): Don't deal with oct
+       and hex and casts to unsigned here...
+       * include/bits/locale_facets.tcc (__int_to_char(_CharT*, long,
+       const _CharT*, ios_base::fmtflags), __int_to_char(_CharT*, long
+       long, const _CharT*, ios_base::fmtflags)): ... do that here,
+       instead, as per Table 57.
+       (num_put<>::_M_insert_int): Tidy treatment of numeric base and
+       sign.
+       * include/std/std_ostream.h (operator<<(short), operator<<(int)):
+       Adjust logic, as per the letter of the resolution of DR117 [WP].
+       * testsuite/22_locale/num_put/put/char/10.cc: New.
+       * testsuite/22_locale/num_put/put/wchar_t/10.cc: Likewise.
+       * testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc:
+       Likewise.
+       * testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc:
+       Likewise.
+
 2005-07-07  David Edelsohn  <edelsohn@gnu.org>
 
        * testsuite/ext/pb_assoc/example/tree_order_statistics_join.cc:
index 7987e67..5fe251b 100644 (file)
@@ -820,15 +820,19 @@ namespace std
       __len = static_cast<int>(__w);
     }
 
-  // Forwarding functions to peel signed from unsigned integer types.
+  // Forwarding functions to peel signed from unsigned integer types and
+  // either cast or compute the absolute value for the former, depending
+  // on __basefield.
   template<typename _CharT>
     inline int
     __int_to_char(_CharT* __bufend, long __v, const _CharT* __lit,
                  ios_base::fmtflags __flags)
     {
-      unsigned long __ul = static_cast<unsigned long>(__v);
-      if (__v < 0)
-       __ul = -__ul;
+      unsigned long __ul = __v;
+      const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
+      if (__builtin_expect(__basefield != ios_base::oct
+                          && __basefield != ios_base::hex, true))
+       __ul = __v < 0 ? -__v : __ul;
       return __int_to_char(__bufend, __ul, __lit, __flags, false);
     }
 
@@ -844,9 +848,11 @@ namespace std
     __int_to_char(_CharT* __bufend, long long __v, const _CharT* __lit,
                  ios_base::fmtflags __flags)
     {
-      unsigned long long __ull = static_cast<unsigned long long>(__v);
-      if (__v < 0)
-       __ull = -__ull;
+      unsigned long long __ull = __v;
+      const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
+      if (__builtin_expect(__basefield != ios_base::oct
+                          && __basefield != ios_base::hex, true))
+       __ull = __v < 0 ? -__v : __ull;
       return __int_to_char(__bufend, __ull, __lit, __flags, false);
     }
 
@@ -966,16 +972,11 @@ namespace std
            else if (__v)
              *--__cs = __lit[__num_base::_S_ominus], ++__len;
          }
-       else if (__basefield == ios_base::oct)
+       else if (__flags & ios_base::showbase && __v)
          {
-           // Octal.
-           if (__flags & ios_base::showbase && __v)
+           if (__basefield == ios_base::oct)
              *--__cs = __lit[__num_base::_S_odigits], ++__len;
-         }
-       else
-         {
-           // Hex.
-           if (__flags & ios_base::showbase && __v)
+           else
              {
                // 'x' or 'X'
                const bool __uppercase = __flags & ios_base::uppercase;
@@ -1213,8 +1214,8 @@ namespace std
   template<typename _CharT, typename _OutIter>
     _OutIter
     num_put<_CharT, _OutIter>::
-    do_put(iter_type __s, ios_base& __b, char_type __fill, long long __v) const
-    { return _M_insert_int(__s, __b, __fill, __v); }
+    do_put(iter_type __s, ios_base& __io, char_type __fill, long long __v) const
+    { return _M_insert_int(__s, __io, __fill, __v); }
 
   template<typename _CharT, typename _OutIter>
     _OutIter
index fc1c56f..b4ea5b9 100644 (file)
@@ -1,6 +1,6 @@
 // ostream classes -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -130,19 +130,8 @@ namespace std
          ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
          try
            {
-             bool __b = false;
-             const char_type __c = this->fill();
-             const ios_base::fmtflags __fmt = (this->flags()
-                                               & ios_base::basefield);
              const __num_put_type& __np = __check_facet(this->_M_num_put);
-             if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
-               {
-                 const unsigned long __l = static_cast<unsigned long>(__n);
-                 __b = __np.put(*this, *this, __c, __l).failed();
-               }
-             else
-               __b = __np.put(*this, *this, __c, __n).failed();
-             if (__b)
+             if (__np.put(*this, *this, this->fill(), __n).failed())
                __err |= ios_base::badbit;
            }
          catch(...)
@@ -188,20 +177,8 @@ namespace std
          ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
          try
            {
-             bool __b = false;
-             const char_type __c = this->fill();
-             const ios_base::fmtflags __fmt = (this->flags()
-                                               & ios_base::basefield);
              const __num_put_type& __np = __check_facet(this->_M_num_put);
-             if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
-               {
-                 const unsigned long long __l = (static_cast<
-                                                 unsigned long long>(__n));
-                 __b = __np.put(*this, *this, __c, __l).failed();
-               }
-             else
-               __b = __np.put(*this, *this, __c, __n).failed();
-             if (__b)
+             if (__np.put(*this, *this, this->fill(), __n).failed())
                __err |= ios_base::badbit;
            }
          catch(...)
index 1c66440..b484cab 100644 (file)
@@ -175,9 +175,9 @@ namespace std
       __ostream_type& 
       operator<<(short __n)
       { 
-       ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
-       if (__fmt & ios_base::oct || __fmt & ios_base::hex)
-         return this->operator<<(static_cast<unsigned long>
+       const ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
+       if (__fmt == ios_base::oct || __fmt == ios_base::hex)
+         return this->operator<<(static_cast<long>
                                  (static_cast<unsigned short>(__n)));
        else
          return this->operator<<(static_cast<long>(__n));
@@ -190,9 +190,9 @@ namespace std
       __ostream_type& 
       operator<<(int __n)
       { 
-       ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
-       if (__fmt & ios_base::oct || __fmt & ios_base::hex)
-         return this->operator<<(static_cast<unsigned long>
+       const ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
+       if (__fmt == ios_base::oct || __fmt == ios_base::hex)
+         return this->operator<<(static_cast<long>
                                  (static_cast<unsigned int>(__n)));
        else
          return this->operator<<(static_cast<long>(__n));
diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/char/10.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/char/10.cc
new file mode 100644 (file)
index 0000000..97c5712
--- /dev/null
@@ -0,0 +1,68 @@
+// 2005-07-11  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2005 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>
+
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  locale loc_c = locale::classic();
+
+  const string empty;
+
+  stringstream ss;
+  ss.imbue(loc_c);
+  const num_put<char>& np = use_facet<num_put<char> >(ss.getloc()); 
+
+  long l = -1;
+  unsigned long ul = 0;
+
+  ss.setf(ios::hex, ios::basefield);
+  np.put(ss.rdbuf(), ss, '+', l);
+  VERIFY( ss.str() != "1" );
+  ss >> ul;
+  VERIFY( ul == static_cast<unsigned long>(l) );
+
+#ifdef _GLIBCXX_USE_LONG_LONG  
+  long long ll = -1LL;
+  unsigned long long ull = 0ULL;
+
+  ss.str(empty);
+  ss.clear();
+  np.put(ss.rdbuf(), ss, '+', ll);
+  VERIFY( ss.str() != "1" );
+  ss >> ull;
+  VERIFY( ull == static_cast<unsigned long long>(ll) );
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
diff --git a/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/10.cc b/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/10.cc
new file mode 100644 (file)
index 0000000..2e9243c
--- /dev/null
@@ -0,0 +1,68 @@
+// 2005-07-11  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2005 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>
+
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  locale loc_c = locale::classic();
+
+  const wstring empty;
+
+  wstringstream ss;
+  ss.imbue(loc_c);
+  const num_put<wchar_t>& np = use_facet<num_put<wchar_t> >(ss.getloc()); 
+
+  long l = -1;
+  unsigned long ul = 0;
+
+  ss.setf(ios::hex, ios::basefield);
+  np.put(ss.rdbuf(), ss, L'+', l);
+  VERIFY( ss.str() != L"1" );
+  ss >> ul;
+  VERIFY( ul == static_cast<unsigned long>(l) );
+
+#ifdef _GLIBCXX_USE_LONG_LONG  
+  long long ll = -1LL;
+  unsigned long long ull = 0ULL;
+
+  ss.str(empty);
+  ss.clear();
+  np.put(ss.rdbuf(), ss, L'+', ll);
+  VERIFY( ss.str() != L"1" );
+  ss >> ull;
+  VERIFY( ull == static_cast<unsigned long long>(ll) );
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc
new file mode 100644 (file)
index 0000000..4382473
--- /dev/null
@@ -0,0 +1,68 @@
+// 2005-07-11  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2005 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.
+
+// 27.6.2.5.2  Arithmetic inserters
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  stringstream ostr1, ostr2, ostr3, ostr4;
+
+  ostr1.setf(ios_base::oct);
+  ostr1.setf(ios_base::hex);
+
+  short s = -1;
+  ostr1 << s;
+  VERIFY( ostr1.str() == "-1" );
+
+  ostr2.setf(ios_base::oct);
+  ostr2.setf(ios_base::hex);
+
+  int i = -1;
+  ostr2 << i;
+  VERIFY( ostr2.str() == "-1" );
+
+  ostr3.setf(ios_base::oct);
+  ostr3.setf(ios_base::hex);
+
+  long l = -1;
+  ostr3 << l;
+  VERIFY( ostr3.str() == "-1" );
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+  ostr4.setf(ios_base::oct);
+  ostr4.setf(ios_base::hex);
+
+  long long ll = -1LL;
+  ostr4 << ll;
+  VERIFY( ostr4.str() == "-1" );
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc
new file mode 100644 (file)
index 0000000..87013e7
--- /dev/null
@@ -0,0 +1,68 @@
+// 2005-07-11  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2005 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.
+
+// 27.6.2.5.2  Arithmetic inserters
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  wstringstream ostr1, ostr2, ostr3, ostr4;
+
+  ostr1.setf(ios_base::oct);
+  ostr1.setf(ios_base::hex);
+
+  short s = -1;
+  ostr1 << s;
+  VERIFY( ostr1.str() == L"-1" );
+
+  ostr2.setf(ios_base::oct);
+  ostr2.setf(ios_base::hex);
+
+  int i = -1;
+  ostr2 << i;
+  VERIFY( ostr2.str() == L"-1" );
+
+  ostr3.setf(ios_base::oct);
+  ostr3.setf(ios_base::hex);
+
+  long l = -1;
+  ostr3 << l;
+  VERIFY( ostr3.str() == L"-1" );
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+  ostr4.setf(ios_base::oct);
+  ostr4.setf(ios_base::hex);
+
+  long long ll = -1LL;
+  ostr4 << ll;
+  VERIFY( ostr4.str() == L"-1" );
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}