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

            Bug ID: 58924
           Summary: Non-member invocation of overload of operator<< when
                    the first argument is a temporary of type
                    std::stringstream
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sir_nawaz959 at yahoo dot com

I'm using GCC-4.8.1 in C++11 Mode.

Consider this code,

#include <sstream>
#include <iostream>

int main()
{
    auto s = static_cast<std::stringstream&>(std::stringstream() << "XYZ" <<
"ABC").str();

    std::cout << s << std::endl;
}

Actual (incorrect) output:

XYZABC

The expected output is an address following by ABC, something like this:

0x400e83ABC


Because `std::stringstream()` is a temporary, so the first invocation of
`operator<<` must resolve to a member function (taking void* as argument) which
would print the address, and then the non-member function should be invoked for
the second `<<`.

Note that this works as expected when I don't use `-std=C++11` (of course, in
that case I use `std::string` instead of `auto`).

Reply via email to