[Bug c++/67773] destructor called on temp object before and named object after move, while not being called on named object before move
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Sep 30 13:49:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67773
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Specifically, a move assignment doesn't destroy anything, it just performs an
assignment. So the named variable is not destroyed, its move assignment
operator is called, which does whatever it is written to do. The temporary is
destroyed at the end of the expression, moving from it doesn't alter its
lifetime in any way. The named variable is destroyed at the end of the block as
usual, move assigning to it doesn't alter its lifetime in any way.
There are online compilers you can use to check the results from various GCC
and Clang releases, e.g. http://melponlorg/wandbox
You will find none of them runs a destructor on the target of a move
assignment, because that's not how C++ works.
More information about the Gcc-bugs
mailing list