This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] DR 60 about tellg, seekg not implemented?


Paolo Carlini wrote:

it looks like we are not fully implementing the resolution of DR 60 [TC]:
tellg and seekg do not construct a sentry object.

Hi again, hi Benjamin.


While investigating this issue, I noticed that libstdc++/8348 is exactly
about it: we were doing the right thing (in my understanding) but we
removed the sentry in order to answer libstdc++/8348.

Therefore, adding back the sentry means, basically, reverting the commit
for 8348: see attached draft patch.

In my opinion, the resolution of DR 60 is pretty clear: tellg and seekg
require a sentry:

http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#60

(about paragraphs 36-38 of 27.6.1.3)

In case we agree that this is the way to go, I would also provide tests
checking that a sentry is actually present, besides amending the existing
ones.

Paolo.
diff -prN libstdc++-v3-orig/include/bits/istream.tcc libstdc++-v3/include/bits/istream.tcc
*** libstdc++-v3-orig/include/bits/istream.tcc	Mon May 24 11:40:53 2004
--- libstdc++-v3/include/bits/istream.tcc	Sat May 29 11:51:23 2004
*************** namespace std
*** 848,860 ****
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
        // DR60.  Do not change _M_gcount.
        pos_type __ret = pos_type(-1);
!       try
  	{
! 	  if (!this->fail())
! 	    __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
  	}
-       catch(...)
- 	{ this->_M_setstate(ios_base::badbit); }
        return __ret;
      }
  
--- 848,865 ----
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
        // DR60.  Do not change _M_gcount.
        pos_type __ret = pos_type(-1);
!       sentry __cerb(*this, true);
!       if (__cerb)
  	{
! 	  try
! 	    {
! 	      if (!this->fail())
! 		__ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
! 						  ios_base::in);
! 	    }
! 	  catch(...)
! 	    { this->_M_setstate(ios_base::badbit); }
  	}
        return __ret;
      }
  
*************** namespace std
*** 865,888 ****
      {
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
        // DR60.  Do not change _M_gcount.
!       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
!       try
  	{
! 	  if (!this->fail())
  	    {
! 	      // 136.  seekp, seekg setting wrong streams?
! 	      const pos_type __p = this->rdbuf()->pubseekpos(__pos,
! 							     ios_base::in);
! 
! 	      // 129. Need error indication from seekp() and seekg()
! 	      if (__p == pos_type(off_type(-1)))
! 		__err |= ios_base::failbit;
  	    }
  	}
-       catch(...)
- 	{ this->_M_setstate(ios_base::badbit); }
-       if (__err)
- 	this->setstate(__err);
        return *this;
      }
  
--- 870,897 ----
      {
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
        // DR60.  Do not change _M_gcount.
!       sentry __cerb(*this, true);
!       if (__cerb)
  	{
! 	  ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	  try
  	    {
! 	      if (!this->fail())
! 		{
! 		  // 136.  seekp, seekg setting wrong streams?
! 		  const pos_type __p = this->rdbuf()->pubseekpos(__pos,
! 								 ios_base::in);
! 
! 		  // 129. Need error indication from seekp() and seekg()
! 		  if (__p == pos_type(off_type(-1)))
! 		    __err |= ios_base::failbit;
! 		}
  	    }
+ 	  catch(...)
+ 	    { this->_M_setstate(ios_base::badbit); }
+ 	  if (__err)
+ 	    this->setstate(__err);
  	}
        return *this;
      }
  
*************** namespace std
*** 893,916 ****
      {
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
        // DR60.  Do not change _M_gcount.
!       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
!       try
  	{
! 	  if (!this->fail())
  	    {
! 	      // 136.  seekp, seekg setting wrong streams?
! 	      const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
! 							     ios_base::in);
! 
! 	      // 129. Need error indication from seekp() and seekg()
! 	      if (__p == pos_type(off_type(-1)))
! 		__err |= ios_base::failbit;
  	    }
  	}
-       catch(...)
- 	{ this->_M_setstate(ios_base::badbit); }
-       if (__err)
- 	this->setstate(__err);
        return *this;
      }
  
--- 902,929 ----
      {
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
        // DR60.  Do not change _M_gcount.
!       sentry __cerb(*this, true);
!       if (__cerb)
  	{
! 	  ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
! 	  try
  	    {
! 	      if (!this->fail())
! 		{
! 		  // 136.  seekp, seekg setting wrong streams?
! 		  const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
! 								 ios_base::in);
! 
! 		  // 129. Need error indication from seekp() and seekg()
! 		  if (__p == pos_type(off_type(-1)))
! 		    __err |= ios_base::failbit;
! 		}
  	    }
+ 	  catch(...)
+ 	    { this->_M_setstate(ios_base::badbit); }
+ 	  if (__err)
+ 	    this->setstate(__err);
  	}
        return *this;
      }
  
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_istream/seekg/char/8348-1.cc libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-1.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_istream/seekg/char/8348-1.cc	Tue Jan  6 13:20:42 2004
--- libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-1.cc	Sat May 29 12:23:54 2004
*************** void test06(void)
*** 40,45 ****
--- 40,46 ----
      iss >> asNum;
      VERIFY( test = iss.eof() );
      VERIFY( test = !iss.fail() );
+     iss.clear(); // Otherwise, seekg fails in the sentry.
      iss.seekg(pos1);
      VERIFY( test = !iss.fail() );
    }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_istream/seekg/char/8348-2.cc libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-2.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_istream/seekg/char/8348-2.cc	Tue Jan  6 13:20:42 2004
--- libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-2.cc	Sat May 29 12:24:16 2004
*************** void test06(void)
*** 40,45 ****
--- 40,46 ----
      iss >> asNum;
      VERIFY( test = iss.eof() );
      VERIFY( test = !iss.fail() );
+     iss.clear(); // Otherwise, seekg fails in the sentry.
      iss.seekg(0, ios_base::beg);
      VERIFY( test = !iss.fail() );
    }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_istream/tellg/char/8348.cc libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/8348.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_istream/tellg/char/8348.cc	Tue Jan  6 13:20:42 2004
--- libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/8348.cc	Sat May 29 12:25:19 2004
*************** void test06(void)
*** 40,45 ****
--- 40,46 ----
      iss >> asNum;
      VERIFY( test = iss.eof() );
      VERIFY( test = !iss.fail() );
+     iss.clear(); // Otherwise, tellg fails in the sentry.
      iss.tellg();
      VERIFY( test = !iss.fail() );
    }
*************** void test06(void)
*** 52,57 ****
--- 53,59 ----
      iss >> asNum;
      VERIFY( test = iss.eof() );
      VERIFY( test = !iss.fail() );
+     iss.clear();
      iss.seekg(0, ios_base::beg);
      VERIFY( test = !iss.fail() );
    }
*************** void test06(void)
*** 64,69 ****
--- 66,72 ----
      iss >> asNum;
      VERIFY( test = iss.eof() );
      VERIFY( test = !iss.fail() );
+     iss.clear();
      iss.seekg(pos1);
      VERIFY( test = !iss.fail() );
    }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]