public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sir_nawaz959 at yahoo dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/58924] New: Non-member invocation of overload of operator<< when the first argument is a temporary of type std::stringstream
Date: Wed, 30 Oct 2013 12:02:00 -0000	[thread overview]
Message-ID: <bug-58924-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2013-10-30 12:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30 12:02 sir_nawaz959 at yahoo dot com [this message]
2013-10-30 13:09 ` [Bug c++/58924] " fanael4 at gmail dot com
2013-10-30 13:37 ` daniel.kruegler at googlemail dot com
2013-10-30 13:48 ` [Bug libstdc++/58924] " redi at gcc dot gnu.org
2013-10-30 13:55 ` sir_nawaz959 at yahoo dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-58924-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).