[Bug c++/17181] New: stringstream temporary stores pointer to string as string

bjornpearson at linuxmail dot org gcc-bugzilla@gcc.gnu.org
Wed Aug 25 07:16:00 GMT 2004


When passing a stringstream temporary to a function the address of the string is
converted to a string and stored in the stringstream.  Replacing the code with
tempBug(stringstream() << 1 << "Hello World!"); has the expected result (minus
the 1 prefix).

Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.1/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk--host=i386-redhat-linux
Thread model: posix
gcc version 3.4.1 20040815 (Red Hat 3.4.1-8)
 /usr/libexec/gcc/i386-redhat-linux/3.4.1/cc1plus -E -quiet -v -D_GNU_SOURCE
sstr.cpp -Wall -o sstr.ii
ignoring nonexistent directory
"/usr/lib/gcc/i386-redhat-linux/3.4.1/../../../../i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i386-redhat-linux/3.4.1/../../../../include/c++/3.4.1
 /usr/lib/gcc/i386-redhat-linux/3.4.1/../../../../include/c++/3.4.1/i386-redhat-linux
 /usr/lib/gcc/i386-redhat-linux/3.4.1/../../../../include/c++/3.4.1/backward
 /usr/local/include
 /usr/lib/gcc/i386-redhat-linux/3.4.1/include
 /usr/include
End of search list.
 /usr/libexec/gcc/i386-redhat-linux/3.4.1/cc1plus -fpreprocessed sstr.ii -quiet
-dumpbase sstr.cpp -auxbase sstr -Wall -version -o sstr.s
GNU C++ version 3.4.1 20040815 (Red Hat 3.4.1-8) (i386-redhat-linux)
        compiled by GNU C version 3.4.1 20040815 (Red Hat 3.4.1-8).
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64542
 as -V -Qy -o sstr.o sstr.s
GNU assembler version 2.15.91.0.2 (i386-redhat-linux) using BFD version
2.15.91.0.2 20040727
 /usr/libexec/gcc/i386-redhat-linux/3.4.1/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o sstr
/usr/lib/gcc/i386-redhat-linux/3.4.1/../../../crt1.o
/usr/lib/gcc/i386-redhat-linux/3.4.1/../../../crti.o
/usr/lib/gcc/i386-redhat-linux/3.4.1/crtbegin.o
-L/usr/lib/gcc/i386-redhat-linux/3.4.1 -L/usr/lib/gcc/i386-redhat-linux/3.4.1
-L/usr/lib/gcc/i386-redhat-linux/3.4.1/../../.. -lstdc++sstr.o -lgcc --as-needed
-lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib/gcc/i386-redhat-linux/3.4.1/crtend.o
/usr/lib/gcc/i386-redhat-linux/3.4.1/../../../crtn.o


--Begin Source--
#include <sstream>
#include <iostream>

int tempBug(std::ostream& os)
{
        std::stringstream& ss = static_cast<std::stringstream &> (os);

        std::cout << ss.str() << std::endl;

        return 0;
}

int main(int argc, char** argv)
{
        return tempBug(std::stringstream() << "Hello World!");
}
--End Source--

-- 
           Summary: stringstream temporary stores pointer to string as
                    string
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bjornpearson at linuxmail dot org
                CC: gcc-bugs at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list