未验证 提交 cc9e8699 编写于 作者: X xiaoye 提交者: GitHub

[clang-tidy] No. 53,54 enable cppcoreguidelines-c-copy-assignment-signature...

[clang-tidy] No. 53,54 enable cppcoreguidelines-c-copy-assignment-signature and bugprone-use-after-move (#56601)
上级 241f97d5
......@@ -43,7 +43,7 @@ bugprone-misplaced-widening-cast,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
-bugprone-unused-return-value,
-bugprone-use-after-move,
bugprone-use-after-move,
-bugprone-virtual-near-miss,
-clang-analyzer-apiModeling.StdCLibraryFunctions,
-clang-analyzer-apiModeling.TrustNonnull,
......@@ -153,7 +153,7 @@ clang-analyzer-unix.Vfork,
-clang-analyzer-valist.ValistBase,
cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-c-copy-assignment-signature,
cppcoreguidelines-c-copy-assignment-signature,
-cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-narrowing-conversions,
......
......@@ -43,7 +43,7 @@ RpcAgent::RpcAgent(std::string name, std::vector<WorkerInfo> infos) {
PADDLE_ENFORCE_EQ(
server_.AddService(rpc_service_.get(), brpc::SERVER_DOESNT_OWN_SERVICE),
0,
platform::errors::Fatal("Fail to add service: %s", name));
platform::errors::Fatal("Fail to add service: %s", name_));
}
int RpcAgent::StartWorker() {
......
......@@ -614,7 +614,6 @@ void ProgramInterpreter::Convert(
for (size_t op_idx = 0; op_idx < op_nums; ++op_idx) {
auto& op_func_node = nodes[op_idx];
auto* dev_ctx_ = stream_analyzer_.ParseDeviceContext(op_func_node);
vec_instruction_.emplace_back(op_idx, std::move(op_func_node), *dev_ctx_);
#ifdef PADDLE_WITH_CUDA
if (FLAGS_new_executor_use_cuda_graph) {
auto& op = op_func_node.operator_base_;
......@@ -637,6 +636,7 @@ void ProgramInterpreter::Convert(
.RecordCapturingDeviceContext(dev_ctx_);
}
#endif
vec_instruction_.emplace_back(op_idx, std::move(op_func_node), *dev_ctx_);
}
BuildOperatorDependences();
......
......@@ -121,7 +121,7 @@ StreamSafeCustomDeviceAllocator::StreamSafeCustomDeviceAllocator(
place_(std::move(place)),
default_stream_(std::move(default_stream)) {
std::lock_guard<SpinLock> lock_guard(allocator_map_lock_);
allocator_map_[place].emplace_back(this);
allocator_map_[place_].emplace_back(this);
}
StreamSafeCustomDeviceAllocator::~StreamSafeCustomDeviceAllocator() {
......
......@@ -130,10 +130,14 @@ class BeamSearchFunctor<phi::CPUContext, T> {
((score == in.score) && (offset < in.offset));
}
inline void operator=(const Item &in) {
offset = in.offset;
id = in.id;
score = in.score;
inline Item &operator=(const Item &in) {
if (this != &in) {
this->offset = in.offset;
this->id = in.id;
this->score = in.score;
return *this;
}
return *this;
}
std::string ToString() {
......
......@@ -57,11 +57,15 @@ SparseCooTensor::SparseCooTensor(const SparseCooTensor& other) {
set_meta(other.meta());
}
SparseCooTensor SparseCooTensor::operator=(const SparseCooTensor& other) {
this->non_zero_elements_ = other.non_zero_elements_;
this->non_zero_indices_ = other.non_zero_indices_;
this->coalesced_ = other.coalesced_;
set_meta(other.meta());
SparseCooTensor& SparseCooTensor::operator=(const SparseCooTensor& other) {
if (this != &other) {
this->non_zero_elements_ = other.non_zero_elements_;
this->non_zero_indices_ = other.non_zero_indices_;
this->coalesced_ = other.coalesced_;
set_meta(other.meta());
return *this;
}
return *this;
}
......
......@@ -58,7 +58,7 @@ class SparseCooTensor : public TensorBase,
SparseCooTensor(SparseCooTensor&& other);
/// \brief SparseCooTensor shallow copy assignment.
SparseCooTensor operator=(const SparseCooTensor& other);
SparseCooTensor& operator=(const SparseCooTensor& other);
/// \brief Destroy the tensor object and release exclusive resources.
virtual ~SparseCooTensor() = default;
......
......@@ -35,10 +35,16 @@ struct GraphWeightedNode {
}
GraphWeightedNode(T node_id, float weight_key, T eid = 0)
: node_id(node_id), weight_key(weight_key), eid(eid) {}
void operator=(const GraphWeightedNode<T>& other) {
node_id = other.node_id;
weight_key = other.weight_key;
eid = other.eid;
GraphWeightedNode& operator=(const GraphWeightedNode<T>& other) {
if (this != &other) {
this->node_id = other.node_id;
this->weight_key = other.weight_key;
this->eid = other.eid;
return *this;
}
return *this;
}
friend bool operator>(const GraphWeightedNode<T>& n1,
const GraphWeightedNode<T>& n2) {
......
......@@ -204,7 +204,13 @@ struct MyClass {
explicit MyClass(int val) : val_(val) {}
MyClass(const MyClass& b) { val_ = b.val_; }
MyClass(MyClass&& b) { val_ = b.val_; }
void operator=(const MyClass& b) { val_ = b.val_; }
MyClass& operator=(const MyClass& b) {
if (this != &b) {
val_ = b.val_;
return *this;
}
return *this;
}
int val_;
};
......@@ -212,7 +218,7 @@ struct MyClass {
TEST(BlockingQueue, MyClassTest) {
BlockingQueue<MyClass> q(2);
MyClass a(200);
q.Send(std::move(a));
q.Send(a);
MyClass b;
q.Receive(&b);
EXPECT_EQ(a.val_, b.val_);
......
......@@ -94,7 +94,7 @@ TEST(pstring, func) {
CHECK_EQ(copy_nchar_str, "AAAAA");
// Test Move Ctor
pstring move_nchar_str(std::move(nchar_str));
pstring move_nchar_str(nchar_str);
CHECK_EQ(move_nchar_str, "AAAAA");
pstring std_str(std::string("BBBB"));
CHECK_EQ(std_str, "BBBB");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册