public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59926] New: Remove temporary move constructor before move assignment
@ 2014-01-23 18:11 arnoux123 at gmail dot com
  2014-01-23 18:14 ` [Bug c++/59926] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: arnoux123 at gmail dot com @ 2014-01-23 18:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59926
           Summary: Remove temporary move constructor before move
                    assignment
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arnoux123 at gmail dot com

When returning an rvalue from a function, the compiler creates a temporary
using
"move constructor" before doing a "move assignment" to the object in the
calling
function. See code below.
Would it be possible to remove this temporary "move constructor" which seems
somewhat redundant.

#include <iostream>
#include <utility>
#include <string>

class Base
{
public:
        Base() { std::cout << this << " Base ctor\n" ; }
        ~Base() { std::cout << this << " Base dtor\n" ; }
        Base(Base const&) { std::cout << this << " Base copy\n" ; }
        Base& operator=(Base const&) { std::cout << this << " Base copy
assign\n" ; return *this; }
        Base(Base&&) { std::cout << this << " Base move\n" ; }
        Base& operator=(Base&&) { std::cout << this << " Base move assign\n" ;
return *this; }
};

class Derived : public Base
{
public:
        Derived(): Base() { std::cout << this << " Derived ctor\n" ; }
        ~Derived() { std::cout << this << " Derived dtor\n" ; }
        Derived(Derived const& o): Base(o) { std::cout << this << " Derived
copy\n" ; }
        Derived(Derived&& o): Base(std::move(o)) { std::cout << this << "
Derived move\n" ; }
        Derived& operator=(Derived const& o) { std::cout << this << " Derived
copy assign\n" ; return (*this) ; }
        Derived& operator=(Derived&& o) { std::cout << this << " Derived move
assign\n" ; Base::operator=(std::move(o)) ; return (*this) ; }
};

Derived f(Derived d) { return (d) ; }

int main()
{
        Derived r ;
        Derived u ;
        u = f(r) ;
        return 0;
}


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

end of thread, other threads:[~2024-03-25 12:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-23 18:11 [Bug c++/59926] New: Remove temporary move constructor before move assignment arnoux123 at gmail dot com
2014-01-23 18:14 ` [Bug c++/59926] " redi at gcc dot gnu.org
2014-01-23 22:15 ` arnoux123 at gmail dot com
2024-03-17  4:49 ` pinskia at gcc dot gnu.org
2024-03-25 12:43 ` redi 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).