-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
array move operator= is actually a copy #95
Comments
The std::exchange requires c++14, however, so you may want to just use
|
@kfsone Sure, it's not a pure move but we're copying a pointer which is instant? Why is this a problem? |
Exactly that you are copying the pointer. If the object you are copying from is a temporary, it will be destroyed immediately after this method. The pointer you copied is now invalid. std::move and std::forward are just casts, it's the operators that have to actually perform the movement. |
Here's a demonstrative example, change the "MOVE_NOT_COPY" on the first line from 0 to 1 to see it operate without leaking/multi-deleting. https://gcc.godbolt.org/z/PWxExbPx1 Note in particular where A#4 and A#7 are ~d relative to the end of scope. Passing an rvalue reference to an object makes it an rvalue. The only reason that the language doesn't automatically delete named rvalues is so that you can reuse their storage, which in turn depends on them having good move operators.
|
reproc/reproc++/include/reproc++/detail/array.hpp
Lines 23 to 30 in 08675b1
The move-assignment operator is not actually moving but copying.
https://gcc.godbolt.org/z/az44M1577
Move should be implemented as swap or exchange:
https://gcc.godbolt.org/z/5fzrhaGvd
The text was updated successfully, but these errors were encountered: