public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59823] New: conversion operator to const X& causes copy-construction of temporary
@ 2014-01-15 11:27 redi at gcc dot gnu.org
  2014-01-15 11:29 ` [Bug c++/59823] [4.7/4.8/4.9 Regression] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-15 11:27 UTC (permalink / raw)
  To: gcc-bugs

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"


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-08-01 18:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-15 11:27 [Bug c++/59823] New: conversion operator to const X& causes copy-construction of temporary redi at gcc dot gnu.org
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

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).