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