2002-11-05 Benjamin Kosnik <bkoz@redhat.com>
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 5 Nov 2002 23:46:22 +0000 (23:46 +0000)
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 5 Nov 2002 23:46:22 +0000 (23:46 +0000)
PR libstdc++/8258
* include/bits/istream.tcc (istream::readsome): Don't set eofbit
for null buffer.
(istream::operator>>(_CharT*)): Use traits_type.
(istream::ws): Same.
(istream::operator>>(string)): Same.
* testsuite/27_io/istream_unformatted.cc (test11): Add.

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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/testsuite/27_io/istream_unformatted.cc

index 12ae0f0..2675d27 100644 (file)
@@ -1,3 +1,13 @@
+2002-11-05  Benjamin Kosnik  <bkoz@redhat.com>
+
+       PR libstdc++/8258
+       * include/bits/istream.tcc (istream::readsome): Don't set eofbit
+       for null buffer.
+       (istream::operator>>(_CharT*)): Use traits_type.
+       (istream::ws): Same.
+       (istream::operator>>(string)): Same.    
+       * testsuite/27_io/istream_unformatted.cc (test11): Add.
+       
 2002-11-05  Paolo Carlini  <pcarlini@unitus.it>
 
        PR libstdc++/8466
@@ -11,7 +21,7 @@
 
        * configure.target (hppa*): Define cpu_include_dir.
        * config/os/hpux/os_defines.h (_GLIBCPP_INST_ATOMICITY_LOCK): Define.
-       * src/misc-inst.cc (std): Instantiate atomicity lock when
+       * src/misc-inst.cc: Instantiate atomicity lock when
        _GLIBCPP_INST_ATOMICITY_LOCK is defined.
        * config/cpu/hppa/atomicity.h: New file.
 
index 617110d..a6e49a9 100644 (file)
@@ -811,8 +811,9 @@ namespace std
        {
          try 
            {
+             // Cannot compare int_type with streamsize generically.
              streamsize __num = this->rdbuf()->in_avail();
-             if (__num > 0)
+             if (__num >= 0)
                {
                  __num = min(__num, __n);
                  if (__num)
@@ -1034,13 +1035,14 @@ namespace std
              int_type __c = __sb->sgetc();
              
              while (__extracted < __num - 1 
-                    && __c != __eof && !__ctype.is(ctype_base::space, __c))
+                    && !_Traits::eq_int_type(__c, __eof)
+                    && !__ctype.is(ctype_base::space, __c))
                {
                  *__s++ = __c;
                  ++__extracted;
                  __c = __sb->snextc();
                }
-             if (__c == __eof)
+             if (_Traits::eq_int_type(__c, __eof))
                __in.setstate(ios_base::eofbit);
 
 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
@@ -1078,9 +1080,11 @@ namespace std
       __streambuf_type* __sb = __in.rdbuf();
       __int_type __c = __sb->sgetc();
 
-      while (__c != __eof && __ctype.is(ctype_base::space, __c))
+      while (!_Traits::eq_int_type(__c, __eof) 
+            && __ctype.is(ctype_base::space, __c))
        __c = __sb->snextc();
-      if (__c == __eof)
+
+       if (_Traits::eq_int_type(__c, __eof))
        __in.setstate(ios_base::eofbit);
 
       return __in;
@@ -1114,13 +1118,14 @@ namespace std
          __int_type __c = __sb->sgetc();
          
          while (__extracted < __n 
-                && __c != __eof && !__ctype.is(ctype_base::space, __c))
+                && !_Traits::eq_int_type(__c, __eof)
+                && !__ctype.is(ctype_base::space, __c))
            {
              __str += _Traits::to_char_type(__c);
              ++__extracted;
              __c = __sb->snextc();
            }
-         if (__c == __eof)
+         if (_Traits::eq_int_type(__c, __eof))
            __in.setstate(ios_base::eofbit);
          __in.width(0);
        }
index 0e98dce..7e449ab 100644 (file)
@@ -551,6 +551,25 @@ test10()
   VERIFY( test );
 }
 
+
+// libstdc++/8258
+class mybuf : public std::basic_streambuf<char> 
+{ };
+
+void test11()
+{
+  bool test = true;
+  using namespace std;
+  char arr[10];
+  mybuf sbuf;
+  basic_istream<char, char_traits<char> > istr(&sbuf);
+  
+  VERIFY(istr.rdstate() == ios_base::goodbit);
+  VERIFY(istr.readsome(arr, 10) == 0);
+  VERIFY(istr.rdstate() == ios_base::goodbit);
+}
+
+
 int 
 main()
 {
@@ -564,6 +583,6 @@ main()
   test08();
   test09();
   test10();
-
+  test11();
   return 0;
 }