This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [v3] libstdc++/6533
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, dje at watson dot ibm dot com, Franz dot Sirl-kernel at lauterbach dot com, mark at codesourcery dot com
- Date: Wed, 1 May 2002 15:39:57 -0700
- Subject: Re: [v3] libstdc++/6533
A better patch: operator* has undefined behavior WRT EOF, but equal does not.
tested x86/linux
tested x86/linux -funsigned-char
this should go in
gcc
gcc-3_1-branch
2002-05-01 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/6533
* include/bits/streambuf_iterator.h (istreambuf_iterator::_M_get): New.
(istreambuf_iterator::equal): Use it.
(istreambuf_iterator::operator*): Use it.
Index: include/bits/streambuf_iterator.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/streambuf_iterator.h,v
retrieving revision 1.6
diff -c -p -r1.6 streambuf_iterator.h
*** include/bits/streambuf_iterator.h 30 Apr 2002 07:22:11 -0000 1.6
--- include/bits/streambuf_iterator.h 1 May 2002 22:16:53 -0000
*************** namespace std
*** 77,100 ****
istreambuf_iterator(streambuf_type* __s) throw()
: _M_sbuf(__s), _M_c(-2) { }
! // NB: This should really have an int_type return
! // value, so "end of stream" postion can be checked without
! // hacking.
char_type
operator*() const
! {
! // The result of operator*() on an end of stream is undefined.
! int_type __ret = traits_type::eof();
! if (_M_sbuf)
! {
! if (_M_c != static_cast<int_type>(-2))
! __ret = _M_c;
! else
! if ((__ret = _M_sbuf->sgetc()) == traits_type::eof())
! _M_sbuf = 0;
! }
! return traits_type::to_char_type(__ret);
! }
istreambuf_iterator&
operator++()
--- 77,86 ----
istreambuf_iterator(streambuf_type* __s) throw()
: _M_sbuf(__s), _M_c(-2) { }
! // NB: The result of operator*() on an end of stream is undefined.
char_type
operator*() const
! { return traits_type::to_char_type(_M_get()); }
istreambuf_iterator&
operator++()
*************** namespace std
*** 124,134 ****
equal(const istreambuf_iterator& __b) const
{
const int_type __eof = traits_type::eof();
! bool __thiseof = traits_type::eq_int_type(this->operator*(), __eof);
! bool __beof = traits_type::eq_int_type(__b.operator*(), __eof);
return (__thiseof && __beof || (!__thiseof && !__beof));
}
#endif
};
template<typename _CharT, typename _Traits>
--- 110,136 ----
equal(const istreambuf_iterator& __b) const
{
const int_type __eof = traits_type::eof();
! bool __thiseof = _M_get() == __eof;
! bool __beof = __b._M_get() == __eof;
return (__thiseof && __beof || (!__thiseof && !__beof));
}
#endif
+
+ private:
+ int_type
+ _M_get() const
+ {
+ int_type __ret = traits_type::eof();
+ if (_M_sbuf)
+ {
+ if (_M_c != static_cast<int_type>(-2))
+ __ret = _M_c;
+ else
+ if ((__ret = _M_sbuf->sgetc()) == traits_type::eof())
+ _M_sbuf = 0;
+ }
+ return __ret;
+ }
};
template<typename _CharT, typename _Traits>