2002-04-18 Benjamin Kosnik <bkoz@redhat.com>
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Apr 2002 23:47:50 +0000 (23:47 +0000)
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Apr 2002 23:47:50 +0000 (23:47 +0000)
* include/bits/localefwd.h (locale::id::_M_id): Do this correctly,
as type safety is important, especially on solaris.
* include/bits/istream.tcc (istream::read): Clean.
(istream::readsome): Same.
* locale.cc: Wrap lines.

* testsuite/21_strings/inserters_extractors.cc: Tweaks.
* testsuite/27_io/instantiations.cc (test): Add bool variable...
* testsuite/21_strings/capacity.cc: Clean.

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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/include/bits/localefwd.h
libstdc++-v3/src/locale.cc
libstdc++-v3/testsuite/21_strings/capacity.cc
libstdc++-v3/testsuite/21_strings/inserters_extractors.cc
libstdc++-v3/testsuite/27_io/instantiations.cc

index 8b509cc..42ac416 100644 (file)
@@ -1,3 +1,15 @@
+2002-04-18  Benjamin Kosnik  <bkoz@redhat.com>
+
+       * include/bits/localefwd.h (locale::id::_M_id): Do this correctly,
+       as type safety is important, especially on solaris.
+       * include/bits/istream.tcc (istream::read): Clean.
+       (istream::readsome): Same.
+       * locale.cc: Wrap lines.
+
+       * testsuite/21_strings/inserters_extractors.cc: Tweaks.
+       * testsuite/27_io/instantiations.cc (test): Add bool variable...
+       * testsuite/21_strings/capacity.cc: Clean.
+               
 2002-04-17  Phil Edwards  <pme@gcc.gnu.org>
 
        * docs/doxygen/doxygroups.cc:  New group on binary searching.
index 9ee38a4..6b2e4ca 100644 (file)
@@ -777,39 +777,28 @@ namespace std
       sentry __cerb(*this, true);
       if (__cerb) 
        {
-         if (__n > 0)
+         try 
            {
-             try 
-               {
-                 const int_type __eof = traits_type::eof();
-                 __streambuf_type* __sb = this->rdbuf();
-                 int_type __c = __sb->sbumpc();        
-                 bool __testeof =  __c == __eof;
-                 
-                 while (_M_gcount < __n - 1 && !__testeof)
-                   {
-                     *__s++ = traits_type::to_char_type(__c);
-                     ++_M_gcount;
-                     __c = __sb->sbumpc();
-                     __testeof = __c == __eof;
-                   }
-                 if (__testeof)
-                   this->setstate(ios_base::eofbit | ios_base::failbit);
-                 else
-                   {
-                     // _M_gcount == __n - 1
-                     *__s++ = traits_type::to_char_type(__c);
-                     ++_M_gcount;
-                   }       
-               }
-             catch(exception& __fail)
+             const int_type __eof = traits_type::eof();
+             __streambuf_type* __sb = this->rdbuf();
+             int_type __c = __sb->sgetc();     
+             
+             while (_M_gcount < __n && __c != __eof)
                {
-                 // 27.6.1.3 paragraph 1
-                 // Turn this on without causing an ios::failure to be thrown.
-                 this->setstate(ios_base::badbit);
-                 if ((this->exceptions() & ios_base::badbit) != 0)
-                   __throw_exception_again;
+                 *__s++ = traits_type::to_char_type(__c);
+                 ++_M_gcount;
+                 __c = __sb->snextc();
                }
+             if (__c == __eof)
+               this->setstate(ios_base::eofbit | ios_base::failbit);
+           }       
+         catch(exception& __fail)
+           {
+             // 27.6.1.3 paragraph 1
+             // Turn this on without causing an ios::failure to be thrown.
+             this->setstate(ios_base::badbit);
+             if ((this->exceptions() & ios_base::badbit) != 0)
+               __throw_exception_again;
            }
        }
       else
@@ -822,32 +811,30 @@ namespace std
     basic_istream<_CharT, _Traits>::
     readsome(char_type* __s, streamsize __n)
     {
-      const int_type __eof = traits_type::eof();
       _M_gcount = 0;
       sentry __cerb(*this, true);
       if (__cerb) 
        {
-         if (__n > 0)
+         try 
            {
-             try 
-               {
-                 streamsize __num = this->rdbuf()->in_avail();
-                 if (__num != static_cast<streamsize>(__eof))
-                   {
-                     __num = min(__num, __n);
-                     _M_gcount = this->rdbuf()->sgetn(__s, __num);
-                   }
-                 else
-                   this->setstate(ios_base::eofbit);               
-               }
-             catch(exception& __fail)
+             const int_type __eof = traits_type::eof(); 
+             streamsize __num = this->rdbuf()->in_avail();
+             if (__num != static_cast<streamsize>(__eof))
                {
-                 // 27.6.1.3 paragraph 1
-                 // Turn this on without causing an ios::failure to be thrown.
-                 this->setstate(ios_base::badbit);
-                 if ((this->exceptions() & ios_base::badbit) != 0)
-                   __throw_exception_again;
+                 __num = min(__num, __n);
+                 if (__num)
+                   _M_gcount = this->rdbuf()->sgetn(__s, __num);
                }
+             else
+               this->setstate(ios_base::eofbit);                   
+           }
+         catch(exception& __fail)
+           {
+             // 27.6.1.3 paragraph 1
+             // Turn this on without causing an ios::failure to be thrown.
+             this->setstate(ios_base::badbit);
+             if ((this->exceptions() & ios_base::badbit) != 0)
+               __throw_exception_again;
            }
        }
       else
index c6daeb6..028c412 100644 (file)
@@ -455,14 +455,11 @@ namespace std
     // counted on to be zero-initialized.
     id();
 
-    size_t
+    inline size_t
     _M_id() const
     {
       if (!_M_index)
-       {
-         __exchange_and_add(&_S_highwater, 1);
-         _M_index = _S_highwater;
-       }
+       _M_index = 1 + __exchange_and_add(&_S_highwater, 1);
       return _M_index - 1;
     }
   };
index 54693cb..26c2834 100644 (file)
@@ -226,7 +226,8 @@ namespace std
   locale::operator==(const locale& __rhs) const throw()
   {
     string __name = this->name();
-    return (_M_impl == __rhs._M_impl || (__name != "*" && __name == __rhs.name()));
+    return (_M_impl == __rhs._M_impl 
+           || (__name != "*" && __name == __rhs.name()));
   }
 
   const locale&
index 3bfb051..be209e0 100644 (file)
@@ -1,6 +1,6 @@
 // 1999-05-11 bkoz
 
-// Copyright (C) 1999 Free Software Foundation, Inc.
+// Copyright (C) 1999, 2002 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
@@ -21,7 +21,6 @@
 // 21.3.3 string capacity
 
 #include <string>
-#include <cstdio>
 #include <testsuite_hooks.h>
 
 template<typename T>
@@ -37,7 +36,7 @@ template<typename T>
 
 struct B { };
 
-bool test01()
+void test01()
 {
   // 1 POD types : resize, capacity, reserve
   bool test = true;
@@ -161,17 +160,11 @@ bool test01()
   VERIFY( b01 == true );
   sz04 = str02.size();  
   VERIFY( sz03 >= sz04 );
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
-  
-  return test;
 }
 
 // libstdc++/4548
 // http://gcc.gnu.org/ml/libstdc++/2001-11/msg00150.html
-bool test02()
+void test02()
 {
   bool test = true;
 
@@ -180,12 +173,6 @@ bool test02()
   std::string str02 = str01;
   str01.reserve(1);
   VERIFY( str01.capacity() == 12 );
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
-
-  return test;
 }
 
 #if !__GXX_WEAK__
@@ -206,7 +193,3 @@ int main()
 
   return 0;
 }
-
-
-
-
index 5d1d9f5..41a9a65 100644 (file)
@@ -1,6 +1,6 @@
 // 1999-07-01 bkoz
 
-// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+// Copyright (C) 1999, 2000, 2001, 2002 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
@@ -53,16 +53,20 @@ bool test01(void)
   std::istringstream istrs01(str01);
   istrs01 >> str10;
   VERIFY( str10 == str02 );
-  try {
-    std::istringstream::int_type i01 = istrs01.peek(); //a-boo
-    VERIFY( std::istringstream::traits_type::to_char_type(i01) == ' ' );
-  }
-  catch(std::exception& fail) {
-    VERIFY( false ); // shouldn't throw
-  }
+  try 
+    {
+      std::istringstream::int_type i01 = istrs01.peek(); //a-boo
+      VERIFY( std::istringstream::traits_type::to_char_type(i01) == ' ' );
+    }
+  catch(std::exception& fail) 
+    {
+      VERIFY( false ); // shouldn't throw
+    }
 
+  istrs01.clear();
   istrs01 >> str10; 
   VERIFY( str10 == str03 ); 
+  istrs01.clear();
   istrs01 >> str10; 
   VERIFY( str10 == str04 ); // sentry picks out the white spaces. . 
 
@@ -72,73 +76,86 @@ bool test01(void)
  
   // istream& getline(istream&, string&, char)
   // istream& getline(istream&, string&)
-  try {
-    getline(istrs01, str10);
-    VERIFY( !istrs01.fail() );
-    VERIFY( !istrs01.eof() );
-    VERIFY( istrs01.good() );
-    VERIFY( str10 == " bay" );
-  }
-  catch(std::exception& fail) {
-    VERIFY( false ); // shouldn't throw
-  }
-
-  try {
-    istrs01.clear();
-    getline(istrs01, str10,'\t');
-    VERIFY( !istrs01.fail() );
-    VERIFY( !istrs01.eof() );
-    VERIFY( istrs01.good() );
-    VERIFY( str10 == str05 );
-  }
-  catch(std::exception& fail) {
-    VERIFY( false ); // shouldn't throw
-  }
-
-  try {
-    istrs01.clear();
-    getline(istrs01, str10,'\t');
-    VERIFY( !istrs01.fail() );
-    VERIFY( !istrs01.eof() );
-    VERIFY( istrs01.good() );
-    VERIFY( str10 == str05 );
-  }
-  catch(std::exception& fail) {
-    VERIFY( false ); // shouldn't throw
-  }
-
-  try {
-    istrs01.clear();
-    getline(istrs01, str10, '.');
-    VERIFY( !istrs01.fail() );
-    VERIFY( istrs01.eof() );
-    VERIFY( !istrs01.good() );
-    VERIFY( str10 == "\t    from Elk Rapids to the point reminds me of miles" );
-  }
-  catch(std::exception& fail) {
-    VERIFY( false ); // shouldn't throw
-  }
-
-  try {
-    getline(istrs02, str10);
-    VERIFY( istrs02.fail() );
-    VERIFY( istrs02.eof() );
-    VERIFY( str10 =="\t    from Elk Rapids to the point reminds me of miles" );
-  }
-  catch(std::exception& fail) {
-    VERIFY( false ); // shouldn't throw
-  }
+  try 
+    {
+      istrs01.clear();
+      getline(istrs01, str10);
+      VERIFY( !istrs01.fail() );
+      VERIFY( !istrs01.eof() );
+      VERIFY( istrs01.good() );
+      VERIFY( str10 == " bay" );
+    }
+  catch(std::exception& fail) 
+    {
+      VERIFY( false ); // shouldn't throw
+    }
+
+  try 
+    {
+      istrs01.clear();
+      getline(istrs01, str10,'\t');
+      VERIFY( !istrs01.fail() );
+      VERIFY( !istrs01.eof() );
+      VERIFY( istrs01.good() );
+      VERIFY( str10 == str05 );
+    }
+  catch(std::exception& fail) 
+    {
+      VERIFY( false ); // shouldn't throw
+    }
+  
+  try 
+    {
+      istrs01.clear();
+      getline(istrs01, str10,'\t');
+      VERIFY( !istrs01.fail() );
+      VERIFY( !istrs01.eof() );
+      VERIFY( istrs01.good() );
+      VERIFY( str10 == str05 );
+    }
+  catch(std::exception& fail) 
+    {
+      VERIFY( false ); // shouldn't throw
+    }
+  
+  try 
+    {
+      istrs01.clear();
+      getline(istrs01, str10, '.');
+      VERIFY( !istrs01.fail() );
+      VERIFY( istrs01.eof() );
+      VERIFY( !istrs01.good() );
+      VERIFY( str10 == "\t    from Elk Rapids to the point reminds me of miles" );
+    }
+  catch(std::exception& fail) 
+    {
+      VERIFY( false ); // shouldn't throw
+    }
 
+  try 
+    {
+      getline(istrs02, str10);
+      VERIFY( istrs02.fail() );
+      VERIFY( istrs02.eof() );
+      VERIFY( str10 =="\t    from Elk Rapids to the point reminds me of miles" );
+    }
+  catch(std::exception& fail) 
+    {
+      VERIFY( false ); // shouldn't throw
+    }
+  
   // ostream& operator<<(ostream&, const basic_string&)
   std::ostringstream ostrs01;
-  try {
-    ostrs01 << str01;
-    VERIFY( ostrs01.str() == str01 );
-  }
-  catch(std::exception& fail) {
-    VERIFY( false );
-  }
-
+  try 
+    {
+      ostrs01 << str01;
+      VERIFY( ostrs01.str() == str01 );
+    }
+  catch(std::exception& fail) 
+    {
+      VERIFY( false );
+    }
+  
   std::string hello_world;
   std::cout << hello_world;
   
index 6f87982..b7ee2b4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002 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
@@ -35,6 +35,7 @@ void
 test01()
 {
   using namespace std;
+  bool test = true;
   string x ("   this is text");
   istringstream  sin (x);
   ostringstream  sout;
@@ -47,7 +48,7 @@ test01()
       >> setprecision(5)
       >> setw(20)
       >> ws;
-  VERIFY(sin);
+  VERIFY(sin.good());
 
   sout << resetiosflags(ios_base::dec)
        << setiosflags(ios_base::dec)
@@ -56,7 +57,7 @@ test01()
        << setprecision(5)
        << setw(20)
        << ends << flush << endl;
-  VERIFY(sout);
+  VERIFY(sout.good());
 }