aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@gcc.gnu.org>2002-11-05 23:46:22 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2002-11-05 23:46:22 +0000
commit112615e7d3db8aae00b002543db3ddf94e8e31a2 (patch)
treea94af8bbee145b96c9c31629957f4c6f8fc298c9
parent81646a31577ecfcccac1ccb662012345361aa253 (diff)
downloadgcc-112615e7d3db8aae00b002543db3ddf94e8e31a2.zip
gcc-112615e7d3db8aae00b002543db3ddf94e8e31a2.tar.gz
gcc-112615e7d3db8aae00b002543db3ddf94e8e31a2.tar.bz2
re PR libstdc++/8258 (basic_istream::readsome() with default buffer change stream state to ios_base::eofbit)
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. From-SVN: r58840
-rw-r--r--libstdc++-v3/ChangeLog12
-rw-r--r--libstdc++-v3/include/bits/istream.tcc19
-rw-r--r--libstdc++-v3/testsuite/27_io/istream_unformatted.cc21
3 files changed, 43 insertions, 9 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 12ae0f0..2675d27 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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.
diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc
index 617110d..a6e49a9 100644
--- a/libstdc++-v3/include/bits/istream.tcc
+++ b/libstdc++-v3/include/bits/istream.tcc
@@ -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);
}
diff --git a/libstdc++-v3/testsuite/27_io/istream_unformatted.cc b/libstdc++-v3/testsuite/27_io/istream_unformatted.cc
index 0e98dce..7e449ab 100644
--- a/libstdc++-v3/testsuite/27_io/istream_unformatted.cc
+++ b/libstdc++-v3/testsuite/27_io/istream_unformatted.cc
@@ -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;
}