public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/59823] New: conversion operator to const X& causes copy-construction of temporary Date: Wed, 15 Jan 2014 11:27:00 -0000 [thread overview] Message-ID: <bug-59823-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59823 Bug ID: 59823 Summary: conversion operator to const X& causes copy-construction of temporary Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org extern "C" int puts(const char*); struct X { X() { } X(const X&) { puts("copy"); } X(X&&) { puts("move"); } X& operator=(const X&) { puts("copy assign"); return *this; } X& operator=(X&&) { puts("move assign"); return *this; } }; struct wrap { wrap(const X& x) : wrapped(&x) { } const X* wrapped; operator const X&() const { return *wrapped; } }; int main() { X x1, x2; wrap w(x2); x1 = w; } When compiled with -std=c++11 the expected output is: copy assign but G++ produces: copy move assign It seems that on the last line of main() G++ incorrectly creates a temporary, doing "x1 = X(w)" instead of "x1 = w"
next reply other threads:[~2014-01-15 11:27 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-01-15 11:27 redi at gcc dot gnu.org [this message] 2014-01-15 11:29 ` [Bug c++/59823] [4.7/4.8/4.9 Regression] " redi at gcc dot gnu.org 2014-01-27 20:09 ` jason at gcc dot gnu.org 2014-01-28 4:32 ` jason at gcc dot gnu.org 2014-01-28 14:03 ` jason at gcc dot gnu.org 2014-04-22 11:38 ` [Bug c++/59823] [4.7/4.8 " jakub at gcc dot gnu.org 2014-04-22 11:48 ` redi at gcc dot gnu.org 2014-08-01 18:34 ` [Bug c++/59823] [4.8 " jason at gcc dot gnu.org 2014-08-01 18:36 ` jason at gcc dot gnu.org
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-59823-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: linkBe 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).