This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug libstdc++/10975] incorrect initial ostringstream::tellp()


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10975



------- Additional Comments From brendan at zen dot org  2003-07-17 16:19 -------
  The -1 that's being received from tellp() is happening because of what's
  being given back by pubseekoff(); that, in turn, is giving the correct
  value.

  In pubseekoff() it calls this->seekoff(), which in sstream.tcc sets up to
  only do anything if its _M_string.capacity() is > 0.

 template <class _CharT, class _Traits, class _Alloc>
    typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
    basic_stringbuf<_CharT, _Traits, _Alloc>::
    seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
    {
       pos_type __ret =  pos_type(off_type(-1)); 
       //...
       if (_M_string.capacity() && (__testin || __testout || __testboth))
	 {
	 //...
	 }
       return __ret;
    }

  Otherwise the method goes out with the default pos_type value of -1.  (see
  below for a note about this)

  To figure out why we might not have anything allocated for the basic_string
  object being used here, we can to dive head-first into the standard to find
  out about the ostringstream object we're using.

  In $27.7.3 it says that basic_ostringstream uses a basic_stringbuf object to
  control the associated storage.

  Looking up basic_stringbuf, in $27.7.1.1.2/1 it notes that the
  basic_stringbuf default ctor "allocates no array object".  Thus by default,
  the capacity of the string will be 0.

  As such, since there's no space yet for seekoff() to move inside the
  basic_stringbuf, it gives back the -1 value which tellp() relays to the call
  in the testcase.

  Thus I believe the library's actually behaving correctly in this example.

  Hope this helps,
  B

  P.S. The returning of -1 isn't precisely what's said in the current
  published standard.  The library working group's Defect Report 55 as seen in
     http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#55
  adjusts the standard after the fact to say in 27.7.1.3 paragraph 13 about
  basic_stringbuf's seekoff() method:
      the return value is pos_type(off_type(-1))
  instead of
      the object stores an invalid stream position
  That DR was just a clarification across the board, and isn't really a part
  of this issue.


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