diff --git a/mindspore/core/base/user_data.h b/mindspore/core/base/user_data.h index 90d90f50356..0085efff2e4 100644 --- a/mindspore/core/base/user_data.h +++ b/mindspore/core/base/user_data.h @@ -31,10 +31,16 @@ class UserData { UserData(const UserData &other) : data_(other.data_ ? std::make_unique(*other.data_) : nullptr) {} UserData(UserData &&other) : data_(std::move(other.data_)) {} UserData &operator=(const UserData &other) { + if (this == &other) { + return *this; + } data_ = (other.data_ ? std::make_unique(*other.data_) : nullptr); return *this; } UserData &operator=(UserData &&other) { + if (this == &other) { + return *this; + } data_ = std::move(other.data_); return *this; } @@ -44,7 +50,7 @@ class UserData { void set(const std::string &key, const std::shared_ptr &value) { InitData(); if (value == nullptr) { - data_->erase(key); + (void)data_->erase(key); } else { data_->insert_or_assign(key, value); }