Merge pull request #713 from dtolnay/selfmove

Remove self assignment checks from move assignment operators
This commit is contained in:
David Tolnay 2021-02-11 23:16:43 -08:00 committed by GitHub
commit 19b488c286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 17 deletions

View File

@ -824,11 +824,9 @@ Vec<T>::~Vec() noexcept {
template <typename T>
Vec<T> &Vec<T>::operator=(Vec &&other) noexcept {
if (this != &other) {
this->drop();
this->repr = other.repr;
new (&other) Vec();
}
this->drop();
this->repr = other.repr;
new (&other) Vec();
return *this;
}

View File

@ -109,11 +109,9 @@ String &String::operator=(const String &other) noexcept {
}
String &String::operator=(String &&other) noexcept {
if (this != &other) {
cxxbridge1$string$drop(this);
this->repr = other.repr;
cxxbridge1$string$new(&other);
}
cxxbridge1$string$drop(this);
this->repr = other.repr;
cxxbridge1$string$new(&other);
return *this;
}
@ -392,13 +390,11 @@ Error &Error::operator=(const Error &other) {
}
Error &Error::operator=(Error &&other) noexcept {
if (this != &other) {
std::exception::operator=(std::move(other));
this->msg = other.msg;
this->len = other.len;
other.msg = nullptr;
other.len = 0;
}
std::exception::operator=(std::move(other));
this->msg = other.msg;
this->len = other.len;
other.msg = nullptr;
other.len = 0;
return *this;
}