From 05739d9e418482fc34f5d21f319594f11ae68c7e Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Mon, 25 Apr 2022 10:08:16 +0800 Subject: [PATCH] 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: tiancaishaonvjituizi <452565578@qq.com> * reformat Signed-off-by: tiancaishaonvjituizi <452565578@qq.com> * reformat Signed-off-by: tiancaishaonvjituizi <452565578@qq.com> * fix ArrayRef constructor following llvm * fix format * fix conflict with master --- paddle/fluid/distributed/test/ctr_accessor_test.cc | 2 +- .../ir/fusion_group/code_generator_tester.cc | 4 ---- .../ir/fusion_group/fusion_group_pass_tester.cc | 8 -------- .../framework/new_executor/interpretercore_util.cc | 4 ++-- paddle/fluid/framework/var_desc.h | 6 ++++++ paddle/fluid/inference/utils/table_printer.cc | 2 +- paddle/fluid/platform/profiler.cc | 2 +- paddle/phi/api/lib/api_gen_utils.cc | 2 +- paddle/phi/api/lib/data_transform.cc | 2 +- paddle/phi/core/compat/arg_map_context.h | 5 +++++ paddle/phi/core/utils/type_registry.h | 3 ++- paddle/utils/array_ref.h | 13 ++++++++++++- 12 files changed, 32 insertions(+), 21 deletions(-) diff --git a/paddle/fluid/distributed/test/ctr_accessor_test.cc b/paddle/fluid/distributed/test/ctr_accessor_test.cc index 258b4d33262..ee893ff01b5 100644 --- a/paddle/fluid/distributed/test/ctr_accessor_test.cc +++ b/paddle/fluid/distributed/test/ctr_accessor_test.cc @@ -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) { diff --git a/paddle/fluid/framework/ir/fusion_group/code_generator_tester.cc b/paddle/fluid/framework/ir/fusion_group/code_generator_tester.cc index f671e0ae769..7b6bbf02510 100644 --- a/paddle/fluid/framework/ir/fusion_group/code_generator_tester.cc +++ b/paddle/fluid/framework/ir/fusion_group/code_generator_tester.cc @@ -420,11 +420,7 @@ std::unique_ptr BuildGraph(bool backward, n->Var()->SetDataType(proto_dtype); } } -#ifdef __clang__ return graph; -#else - return std::move(graph); -#endif } std::unordered_set DistilGradNodes( diff --git a/paddle/fluid/framework/ir/fusion_group/fusion_group_pass_tester.cc b/paddle/fluid/framework/ir/fusion_group/fusion_group_pass_tester.cc index d14c7e433bd..db22c03a7d9 100644 --- a/paddle/fluid/framework/ir/fusion_group/fusion_group_pass_tester.cc +++ b/paddle/fluid/framework/ir/fusion_group/fusion_group_pass_tester.cc @@ -63,11 +63,7 @@ std::unique_ptr BuildElementwiseListGraph(bool backward = false) { n->Var()->SetDataType(proto::VarType::FP32); } } -#ifdef __clang__ return graph; -#else - return std::move(graph); -#endif } std::unique_ptr BuildElementwiseTreeGraph(bool backward = false) { @@ -125,11 +121,7 @@ std::unique_ptr 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, std::string prefix) { diff --git a/paddle/fluid/framework/new_executor/interpretercore_util.cc b/paddle/fluid/framework/new_executor/interpretercore_util.cc index 71893d661ed..d6de37a72c7 100644 --- a/paddle/fluid/framework/new_executor/interpretercore_util.cc +++ b/paddle/fluid/framework/new_executor/interpretercore_util.cc @@ -741,7 +741,7 @@ std::map> 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> build_op_downstream_map( @@ -995,7 +995,7 @@ std::map> build_op_downstream_map( std::ostream_iterator(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 diff --git a/paddle/fluid/framework/var_desc.h b/paddle/fluid/framework/var_desc.h index a20ef58f9c9..0f8c10604f3 100644 --- a/paddle/fluid/framework/var_desc.h +++ b/paddle/fluid/framework/var_desc.h @@ -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_; } diff --git a/paddle/fluid/inference/utils/table_printer.cc b/paddle/fluid/inference/utils/table_printer.cc index bd19320cbe6..628465c423b 100644 --- a/paddle/fluid/inference/utils/table_printer.cc +++ b/paddle/fluid/inference/utils/table_printer.cc @@ -53,7 +53,7 @@ std::string TablePrinter::PrintTable() { AddRowDivider(ss); - return std::move(ss.str()); + return ss.str(); } TablePrinter::TablePrinter(const std::vector& header) { diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 8fa48ffcfb1..75abf36e676 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -612,7 +612,7 @@ static std::map 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( diff --git a/paddle/phi/api/lib/api_gen_utils.cc b/paddle/phi/api/lib/api_gen_utils.cc index e0c910ba3d6..a0fd42d769a 100644 --- a/paddle/phi/api/lib/api_gen_utils.cc +++ b/paddle/phi/api/lib/api_gen_utils.cc @@ -41,7 +41,7 @@ std::unique_ptr> TensorToDenseTensor( *std::dynamic_pointer_cast(t.impl())); } - return std::move(pt_tensors); + return pt_tensors; } std::shared_ptr TensorToSelectedRows(const Tensor& tensor) { diff --git a/paddle/phi/api/lib/data_transform.cc b/paddle/phi/api/lib/data_transform.cc index 65cb37d4142..58827a98503 100644 --- a/paddle/phi/api/lib/data_transform.cc +++ b/paddle/phi/api/lib/data_transform.cc @@ -253,7 +253,7 @@ std::unique_ptr> PrepareData( } } - return std::move(pt_tensors); + return pt_tensors; } } // namespace experimental diff --git a/paddle/phi/core/compat/arg_map_context.h b/paddle/phi/core/compat/arg_map_context.h index 102dca48b99..f807f268a2d 100644 --- a/paddle/phi/core/compat/arg_map_context.h +++ b/paddle/phi/core/compat/arg_map_context.h @@ -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; diff --git a/paddle/phi/core/utils/type_registry.h b/paddle/phi/core/utils/type_registry.h index f27c3db2275..5b64dbd0164 100644 --- a/paddle/phi/core/utils/type_registry.h +++ b/paddle/phi/core/utils/type_registry.h @@ -50,7 +50,8 @@ template TypeInfo TypeRegistry::RegisterType(const std::string& type) { std::lock_guard guard(mutex_); assert(name_to_id_.find(type) == name_to_id_.end()); - assert(names_.size() < std::numeric_limits::max()); + assert(names_.size() < static_cast( + std::numeric_limits::max())); int8_t id = static_cast(names_.size()); names_.emplace_back(type); name_to_id_[type] = id; diff --git a/paddle/utils/array_ref.h b/paddle/utils/array_ref.h index d2ab762bb15..78871092593 100644 --- a/paddle/utils/array_ref.h +++ b/paddle/utils/array_ref.h @@ -96,10 +96,21 @@ class ArrayRef { template /*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 &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 from ArrayRef. This uses SFINAE to /// ensure that only ArrayRefs of pointers can be converted. -- GitLab