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 c++/10975] New: 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

           Summary: incorrect initial ostringstream::tellp()
           Product: gcc
           Version: 3.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: from-bugzilla@geek-central.gen.nz
                CC: gcc-bugs@gcc.gnu.org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

When a new ostringstream object is created but nothing has been written 
to it yet, the tellp() method returns an offset of -1, instead of 0.

Example program:

#include <string>
#include <iostream>
#include <fstream>
#include <sstream>

int main
  (
    int argc,
    const char * const * argv,
    const char * const * envp
  )
  {
    std::ostringstream Stream1;
    std::ofstream Stream2("junk.tmp");
#if 0
    Stream1 << " ";
    Stream2 << " ";
#endif
    std::cout
        << "sstream.tellp() = "
        << Stream1.tellp()
        << ", fstream.tellp() = "
        << Stream2.tellp()
"test.cpp" 27L, 434C written
$ g++ -o test test.cpp
$ less test.cpp
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>

int main
  (
    int argc,
    const char * const * argv,
    const char * const * envp
  )
  {
        std::ostringstream Stream1;
        std::ofstream Stream2("junk.tmp");
#if 0
        Stream1 << " ";
        Stream2 << " ";
#endif
        std::cout
                << "sstream.tellp() = "
                << Stream1.tellp()
                << ", fstream.tellp() = "
                << Stream2.tellp()
                << std::endl;
        return
                0;
  } /*main*/

Output from above:

sstream.tellp() = -1, fstream.tellp() = 0

If you change the "#if 0" line to "#if 1", the output becomes

sstream.tellp() = 1, fstream.tellp() = 1



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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