From 8fce6585b283d958e34afed6fab0d31a4f951c76 Mon Sep 17 00:00:00 2001 From: lianliguang Date: Wed, 16 Mar 2022 14:46:28 +0800 Subject: [PATCH] fix code check --- mindspore/core/base/user_data.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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); }