cpp: Fix evmc::result's move assignment operator

This commit is contained in:
Paweł Bylica 2019-05-14 12:03:29 +02:00
parent 3c91910f52
commit cea8d3a5b5
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
1 changed files with 11 additions and 5 deletions

View File

@ -39,16 +39,22 @@ public:
/// Move constructor. /// Move constructor.
result(result&& other) noexcept : evmc_result{other} result(result&& other) noexcept : evmc_result{other}
{ {
// Disable releaser of the rvalue object. other.release = nullptr; // Disable releasing of the rvalue object.
other.release = nullptr;
} }
result(result const&) = delete; result(result const&) = delete;
/// Move-and-swap assignment operator. /// Move assignment operator.
result& operator=(result other) noexcept ///
/// The self-assigment MUST never happen.
///
/// @param other The other result object.
/// @return The reference to the left-hand side object.
result& operator=(result&& other) noexcept
{ {
std::swap(*this, other); this->~result(); // Release this object.
static_cast<evmc_result&>(*this) = other; // Copy data.
other.release = nullptr; // Disable releasing of the rvalue object.
return *this; return *this;
} }