未验证 提交 05739d9e 编写于 作者: T tiancaishaonvjituizi 提交者: GitHub

fix incorrect usages of std::move and other compile errors (#41045)

* fix bug of std::move and others

* fix an compile error in debug mode

* fix wrong copy assignment operator
Signed-off-by: Ntiancaishaonvjituizi <452565578@qq.com>

* reformat
Signed-off-by: Ntiancaishaonvjituizi <452565578@qq.com>

* reformat
Signed-off-by: Ntiancaishaonvjituizi <452565578@qq.com>

* fix ArrayRef constructor following llvm

* fix format

* fix conflict with master
上级 3a0d7bf0
......@@ -61,7 +61,7 @@ TableAccessorParameter gen_param() {
naive_param->add_weight_bounds(-10.0);
naive_param->add_weight_bounds(10.0);
return std::move(param);
return param;
}
TEST(downpour_feature_value_accessor_test, test_shrink) {
......
......@@ -420,11 +420,7 @@ std::unique_ptr<paddle::framework::ir::Graph> BuildGraph(bool backward,
n->Var()->SetDataType(proto_dtype);
}
}
#ifdef __clang__
return graph;
#else
return std::move(graph);
#endif
}
std::unordered_set<paddle::framework::ir::Node*> DistilGradNodes(
......
......@@ -63,11 +63,7 @@ std::unique_ptr<Graph> BuildElementwiseListGraph(bool backward = false) {
n->Var()->SetDataType(proto::VarType::FP32);
}
}
#ifdef __clang__
return graph;
#else
return std::move(graph);
#endif
}
std::unique_ptr<Graph> BuildElementwiseTreeGraph(bool backward = false) {
......@@ -125,11 +121,7 @@ std::unique_ptr<Graph> BuildElementwiseTreeGraph(bool backward = false) {
n->Var()->SetDataType(proto::VarType::FP32);
}
}
#ifdef __clang__
return graph;
#else
return std::move(graph);
#endif
}
int TestMain(std::unique_ptr<Graph> graph, std::string prefix) {
......
......@@ -741,7 +741,7 @@ std::map<int, std::list<int>> get_downstream_map(
VLOG(6) << "downstream count: " << downstream_map_count();
VLOG(6) << "downstream_map: " << std::endl << downstream_map_to_str();
return std::move(downstream);
return downstream;
}
std::map<int, std::list<int>> build_op_downstream_map(
......@@ -995,7 +995,7 @@ std::map<int, std::list<int>> build_op_downstream_map(
std::ostream_iterator<int>(oss, " "));
VLOG(10) << oss.str();
}
return std::move(get_downstream_map(op2dependences, op_happens_before));
return get_downstream_map(op2dependences, op_happens_before);
}
} // namespace interpreter
......
......@@ -74,6 +74,12 @@ class VarDesc {
: desc_(other.desc_),
attrs_(other.attrs_),
original_id_(other.original_id_) {}
VarDesc &operator=(const VarDesc &other) {
desc_ = other.desc_;
attrs_ = other.attrs_;
original_id_ = other.original_id_;
return *this;
}
proto::VarDesc *Proto() { return &desc_; }
......
......@@ -53,7 +53,7 @@ std::string TablePrinter::PrintTable() {
AddRowDivider(ss);
return std::move(ss.str());
return ss.str();
}
TablePrinter::TablePrinter(const std::vector<std::string>& header) {
......
......@@ -612,7 +612,7 @@ static std::map<uint64_t, ThreadEvents> DockHostEventRecorderHostPart() {
auto host_evt_sec = HostEventRecorder::GetInstance().GatherEvents();
EmulateEventPushAndPop(host_evt_sec, &thr_events);
EmulateCPURecordsAdd(host_evt_sec);
return std::move(thr_events);
return thr_events;
}
static void DockHostEventRecorderDevicePart(
......
......@@ -41,7 +41,7 @@ std::unique_ptr<std::vector<phi::DenseTensor>> TensorToDenseTensor(
*std::dynamic_pointer_cast<phi::DenseTensor>(t.impl()));
}
return std::move(pt_tensors);
return pt_tensors;
}
std::shared_ptr<phi::SelectedRows> TensorToSelectedRows(const Tensor& tensor) {
......
......@@ -253,7 +253,7 @@ std::unique_ptr<std::vector<phi::DenseTensor>> PrepareData(
}
}
return std::move(pt_tensors);
return pt_tensors;
}
} // namespace experimental
......
......@@ -58,6 +58,11 @@ struct KernelSignature {
// TODO(chenweihang): add assign constructor to solve windows compile
// problem, remove it later
KernelSignature(const KernelSignature& other)
: name(other.name),
input_names(other.input_names),
attr_names(other.attr_names),
output_names(other.output_names) {}
KernelSignature& operator=(const KernelSignature& other) {
name = other.name;
input_names = other.input_names;
......
......@@ -50,7 +50,8 @@ template <typename BaseT>
TypeInfo<BaseT> TypeRegistry<BaseT>::RegisterType(const std::string& type) {
std::lock_guard<std::mutex> guard(mutex_);
assert(name_to_id_.find(type) == name_to_id_.end());
assert(names_.size() < std::numeric_limits<int8_t>::max());
assert(names_.size() < static_cast<decltype(names_.size())>(
std::numeric_limits<int8_t>::max()));
int8_t id = static_cast<int8_t>(names_.size());
names_.emplace_back(type);
name_to_id_[type] = id;
......
......@@ -96,10 +96,21 @@ class ArrayRef {
template <size_t N>
/*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
/// Construct an ArrayRef from a std::initializer_list.
/// Construct an ArrayRef from a std::initializer_list.
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9
// Disable gcc's warning in this constructor as it generates an enormous
// amount
// of messages. Anyone using ArrayRef should already be aware of the fact that
// it does not do lifetime extension.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winit-list-lifetime"
#endif
/*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
: Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()),
Length(Vec.size()) {}
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9
#pragma GCC diagnostic pop
#endif
/// Construct an ArrayRef<const T*> from ArrayRef<T*>. This uses SFINAE to
/// ensure that only ArrayRefs of pointers can be converted.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册