The function seekp(pos_type) fails on an empty stream,
even when the target position is the value returned
by tellp.

---------------------------------------

#include <ostream>
#include <sstream>
#include <iostream>

int
main()
{
    std::ios::pos_type const
                        err = std::ios::pos_type( std::ios::off_type( -1 ) ) ;
    std::ostringstream  os ;
    std::ios::pos_type  pos = os.tellp() ;
    if ( pos == err ) {
        std::cout << "tell failed" << std::endl ;
    } else {
        os.seekp( pos ) ;
        if ( ! os ) {
            std::cout << "seek failed" << std::endl ;
        }
    }
    return 0 ;
}
---------------------------------------
Outputs "seek failed".  According to the standard,
seekp() calls seekpos() in stringbug, which can
only fail (here) if the position is invalide.
And tellp() cannot return an invalide position
other than -1 (correctly casted).


-- 
           Summary: Error when seeking on an ostringstream
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jkanze at cheuvreux dot com
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8


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

Reply via email to