This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
libstdc++/8348
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 31 Oct 2002 23:38:16 -0600
- Subject: libstdc++/8348
Low hanging fruit.
tested x86/linux
2002-10-31 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/8348
* include/bits/istream.tcc (istream::tellg): Remove sentry bits.
(istream::seekg): Same.
* testsuite/27_io/istream_seeks.cc (test06): New.
Index: include/bits/istream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/istream.tcc,v
retrieving revision 1.34
diff -c -p -r1.34 istream.tcc
*** include/bits/istream.tcc 9 Aug 2002 06:00:17 -0000 1.34
--- include/bits/istream.tcc 1 Nov 2002 05:36:42 -0000
*************** namespace std
*** 935,957 ****
tellg(void)
{
pos_type __ret = pos_type(-1);
! _M_gcount = 0;
! sentry __cerb(*this, true);
! if (__cerb)
! {
! try
! {
! __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
! }
! 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;
! }
! }
return __ret;
}
--- 935,942 ----
tellg(void)
{
pos_type __ret = pos_type(-1);
! if (!this->fail())
! __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
return __ret;
}
*************** namespace std
*** 962,989 ****
seekg(pos_type __pos)
{
_M_gcount = 0;
! sentry __cerb(*this, true);
! if (__cerb)
{
- try
- {
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 136. seekp, seekg setting wrong streams?
! pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
// 129. Need error indication from seekp() and seekg()
! if (__err == pos_type(off_type(-1)))
! this->setstate(ios_base::failbit);
#endif
- }
- 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;
- }
}
return *this;
}
--- 947,962 ----
seekg(pos_type __pos)
{
_M_gcount = 0;
! if (!this->fail())
{
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 136. seekp, seekg setting wrong streams?
! pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
// 129. Need error indication from seekp() and seekg()
! if (__err == pos_type(off_type(-1)))
! this->setstate(ios_base::failbit);
#endif
}
return *this;
}
*************** namespace std
*** 994,1022 ****
seekg(off_type __off, ios_base::seekdir __dir)
{
_M_gcount = 0;
! sentry __cerb(*this, true);
! if (__cerb)
{
- try
- {
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 136. seekp, seekg setting wrong streams?
! pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
! ios_base::in);
// 129. Need error indication from seekp() and seekg()
! if (__err == pos_type(off_type(-1)))
! this->setstate(ios_base::failbit);
#endif
- }
- 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;
- }
}
return *this;
}
--- 967,983 ----
seekg(off_type __off, ios_base::seekdir __dir)
{
_M_gcount = 0;
! if (!this->fail())
{
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 136. seekp, seekg setting wrong streams?
! pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
! ios_base::in);
// 129. Need error indication from seekp() and seekg()
! if (__err == pos_type(off_type(-1)))
! this->setstate(ios_base::failbit);
#endif
}
return *this;
}
Index: testsuite/27_io/istream_seeks.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/istream_seeks.cc,v
retrieving revision 1.12
diff -c -p -r1.12 istream_seeks.cc
*** testsuite/27_io/istream_seeks.cc 21 Jun 2002 20:21:03 -0000 1.12
--- testsuite/27_io/istream_seeks.cc 1 Nov 2002 05:36:43 -0000
*************** bool test01()
*** 55,65 ****
p4 = ifs2.tellg();
VERIFY( p3 == p4 );
-
- #ifdef DEBUG_ASSERT
- assert(test);
- #endif
-
return test;
}
--- 55,60 ----
*************** void test04(void)
*** 237,246 ****
if01.peek();
pos02 = if01.tellg();
VERIFY( pos02 == pos01 );
-
- #ifdef DEBUG_ASSERT
- assert(test);
- #endif
}
// stringstreams
--- 232,237 ----
*************** void test05(void)
*** 351,360 ****
VERIFY( state01 == state02 );
pos06 = is03.tellg();
VERIFY( pos05 == pos06 );
! #ifdef DEBUG_ASSERT
! assert(test);
! #endif
}
int main()
--- 342,391 ----
VERIFY( state01 == state02 );
pos06 = is03.tellg();
VERIFY( pos05 == pos06 );
+ }
! // libstdc++/8348
! void test06(void)
! {
! using namespace std;
! bool test = true;
! string num1("555");
!
! // tellg
! {
! istringstream iss(num1);
! istream::pos_type pos1 = iss.tellg();
! int asNum = 0;
! iss >> asNum;
! VERIFY( test = iss.eof() );
! VERIFY( test = !iss.fail() );
! iss.tellg();
! VERIFY( test = !iss.fail() );
! }
!
! // seekg
! {
! istringstream iss(num1);
! istream::pos_type pos1 = iss.tellg();
! int asNum = 0;
! iss >> asNum;
! VERIFY( test = iss.eof() );
! VERIFY( test = !iss.fail() );
! iss.seekg(0, ios_base::beg);
! VERIFY( test = !iss.fail() );
! }
!
! // seekg
! {
! istringstream iss(num1);
! istream::pos_type pos1 = iss.tellg();
! int asNum = 0;
! iss >> asNum;
! VERIFY( test = iss.eof() );
! VERIFY( test = !iss.fail() );
! iss.seekg(pos1);
! VERIFY( test = !iss.fail() );
! }
}
int main()
*************** int main()
*** 366,371 ****
--- 397,404 ----
test04();
test05();
+
+ test06();
return 0;
}