From c5fe109ba3b23cd3c94db7e285c1dc3cdd226424 Mon Sep 17 00:00:00 2001 From: Wang Xin Date: Mon, 24 Oct 2022 10:25:21 +0800 Subject: [PATCH] [CodeStyle] fix macos inconsistent-missing-override warnings and add -Werror (#47264) * fix macos inconsistent-missing-override warnings * fix inconsistent-missing-override error in test --- cmake/flags.cmake | 3 ++- paddle/fluid/eager/accumulation/accumulation_node.h | 2 +- paddle/fluid/eager/custom_operator/custom_operator_node.h | 4 ++-- paddle/fluid/framework/infershape_utils.h | 6 +++--- paddle/fluid/imperative/infer_var_type_context.h | 4 ++-- paddle/fluid/inference/api/analysis_predictor.h | 6 +++--- .../allocation/auto_growth_best_fit_allocator_test.cc | 4 ++-- paddle/fluid/operators/cross_entropy_op.cc | 6 +++--- paddle/fluid/operators/decode_jpeg_op.cc | 2 +- paddle/fluid/operators/elementwise/elementwise_div_op.h | 2 +- paddle/fluid/operators/elementwise/elementwise_mul_op.h | 2 +- paddle/fluid/operators/elementwise/elementwise_op.h | 6 +++--- paddle/fluid/operators/inplace_abn_op.cc | 2 +- paddle/fluid/operators/optimizers/sgd_op.cc | 2 +- paddle/fluid/operators/pad2d_op.cc | 2 +- 15 files changed, 27 insertions(+), 26 deletions(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index b8a37b5513c..2ec63282ee1 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -214,7 +214,8 @@ if(APPLE) CACHE STRING "Build architectures for OSX" FORCE) endif() # On Mac OS X register class specifier is deprecated and will cause warning error on latest clang 10.0 - set(COMMON_FLAGS -Wno-deprecated-register -Werror=format) + set(COMMON_FLAGS -Wno-deprecated-register -Werror=format + -Werror=inconsistent-missing-override) endif() if(WITH_HETERPS AND WITH_PSLIB) diff --git a/paddle/fluid/eager/accumulation/accumulation_node.h b/paddle/fluid/eager/accumulation/accumulation_node.h index f8e2c4327e1..dcac3c5a0e1 100644 --- a/paddle/fluid/eager/accumulation/accumulation_node.h +++ b/paddle/fluid/eager/accumulation/accumulation_node.h @@ -46,7 +46,7 @@ class GradNodeAccumulation : public GradNodeBase { void ClearTensorWrappers() override { VLOG(5) << "Do nothing here now"; } - std::string name() { return "GradNodeAccumulation"; } + std::string name() override { return "GradNodeAccumulation"; } /** * Register ReduceHook diff --git a/paddle/fluid/eager/custom_operator/custom_operator_node.h b/paddle/fluid/eager/custom_operator/custom_operator_node.h index 580adef6d06..d5df505eeca 100644 --- a/paddle/fluid/eager/custom_operator/custom_operator_node.h +++ b/paddle/fluid/eager/custom_operator/custom_operator_node.h @@ -46,7 +46,7 @@ class RunCustomOpNode : public GradNodeBase { bool is_new_grad = false) // NOLINT override; - std::string name() { + std::string name() override { return paddle::string::Sprintf("RunCustomOpNode: %s_grad", op_type_); } @@ -116,7 +116,7 @@ class RunCustomOpDoubleGradNode : public GradNodeBase { bool is_new_grad = false) // NOLINT override; - std::string name() { + std::string name() override { return paddle::string::Sprintf("RunCustomOpDoubleGradNode: %s_grad_grad", op_type_); } diff --git a/paddle/fluid/framework/infershape_utils.h b/paddle/fluid/framework/infershape_utils.h index d85c550dc0d..9d284dd8a2a 100644 --- a/paddle/fluid/framework/infershape_utils.h +++ b/paddle/fluid/framework/infershape_utils.h @@ -59,9 +59,9 @@ class CompatMetaTensor : public phi::MetaTensor { bool initialized() const override { return initialized_; }; - bool is_selected_rows() const; - bool is_tensor_array() const; - bool is_dense() const; + bool is_selected_rows() const override; + bool is_tensor_array() const override; + bool is_dense() const override; operator unspecified_bool_type() const override { return initialized_ ? unspecified_bool_true : 0; diff --git a/paddle/fluid/imperative/infer_var_type_context.h b/paddle/fluid/imperative/infer_var_type_context.h index 14a8e5d52a0..36558366e1d 100644 --- a/paddle/fluid/imperative/infer_var_type_context.h +++ b/paddle/fluid/imperative/infer_var_type_context.h @@ -68,12 +68,12 @@ class RuntimeInferVarTypeContext : public framework::InferVarTypeContext { return (it != outputs_.end() && it->second.size() > 0); } - size_t InputSize(const std::string& name) const { + size_t InputSize(const std::string& name) const override { return inputs_.at(name).size(); } const std::string& InputVarName(const std::string& name, - const int index = 0) const { + const int index = 0) const override { return GetNameFromVar(inputs_.at(name)[index]); } diff --git a/paddle/fluid/inference/api/analysis_predictor.h b/paddle/fluid/inference/api/analysis_predictor.h index bb196e2ef54..d1dd921db14 100644 --- a/paddle/fluid/inference/api/analysis_predictor.h +++ b/paddle/fluid/inference/api/analysis_predictor.h @@ -143,13 +143,13 @@ class AnalysisPredictor : public PaddlePredictor { /// /// \return input names /// - std::vector GetInputNames(); + std::vector GetInputNames() override; /// /// \brief Get the output names /// /// \return output names /// - std::vector GetOutputNames(); + std::vector GetOutputNames() override; /// /// \brief Get the Input Tensor object @@ -227,7 +227,7 @@ class AnalysisPredictor : public PaddlePredictor { /// \brief Clear the intermediate tensors of the predictor /// /// - void ClearIntermediateTensor(); + void ClearIntermediateTensor() override; /// /// \brief Release all tmp tensor to compress the size of the memory pool. diff --git a/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator_test.cc b/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator_test.cc index 441e80dfa4f..890ebde2aa3 100644 --- a/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator_test.cc +++ b/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator_test.cc @@ -33,7 +33,7 @@ class RecordedAllocator : public Allocator { return new Allocation(malloc(size), size, platform::CPUPlace()); } - void FreeImpl(phi::Allocation *allocation) { + void FreeImpl(phi::Allocation *allocation) override { allocated_size_ -= allocation->size(); free(allocation->ptr()); delete allocation; @@ -88,7 +88,7 @@ class LimitedResourceAllocator : public Allocator { return new Allocation(malloc(size), size, platform::CPUPlace()); } - void FreeImpl(phi::Allocation *allocation) { + void FreeImpl(phi::Allocation *allocation) override { allocated_size_ -= allocation->size(); free(allocation->ptr()); delete allocation; diff --git a/paddle/fluid/operators/cross_entropy_op.cc b/paddle/fluid/operators/cross_entropy_op.cc index 3bc62462eb6..99e67406c3c 100644 --- a/paddle/fluid/operators/cross_entropy_op.cc +++ b/paddle/fluid/operators/cross_entropy_op.cc @@ -346,14 +346,14 @@ class CrossEntropyGradientOp2 : public CrossEntropyGradientOpBase { } protected: - virtual framework::DDim GetXDim(framework::InferShapeContext* ctx) const { + framework::DDim GetXDim(framework::InferShapeContext* ctx) const override { auto x_shape = ctx->GetInputDim("XShape"); return framework::DDim(x_shape.Get(), x_shape.size() - 1); } - virtual const char* VarNameWithXLoD() const { return "XShape"; } + const char* VarNameWithXLoD() const override { return "XShape"; } - virtual bool IsSoftLabel(framework::InferShapeContext* ctx) const { + bool IsSoftLabel(framework::InferShapeContext* ctx) const override { return false; } }; diff --git a/paddle/fluid/operators/decode_jpeg_op.cc b/paddle/fluid/operators/decode_jpeg_op.cc index 973552adb5e..acb94f57bf4 100644 --- a/paddle/fluid/operators/decode_jpeg_op.cc +++ b/paddle/fluid/operators/decode_jpeg_op.cc @@ -41,7 +41,7 @@ class DecodeJpegOp : public framework::OperatorWithKernel { framework::OpKernelType GetKernelTypeForVar( const std::string& var_name, const phi::DenseTensor& tensor, - const framework::OpKernelType& expected_kernel_type) const { + const framework::OpKernelType& expected_kernel_type) const override { if (var_name == "X") { return expected_kernel_type; } diff --git a/paddle/fluid/operators/elementwise/elementwise_div_op.h b/paddle/fluid/operators/elementwise/elementwise_div_op.h index c8289ab098a..236b40c1222 100644 --- a/paddle/fluid/operators/elementwise/elementwise_div_op.h +++ b/paddle/fluid/operators/elementwise/elementwise_div_op.h @@ -51,7 +51,7 @@ class ElementwiseDivOpDoubleGrad : public framework::OperatorWithKernel { framework::OpKernelType GetKernelTypeForVar( const std::string& var_name, const phi::DenseTensor& tensor, - const framework::OpKernelType& expected_kernel_type) const { + const framework::OpKernelType& expected_kernel_type) const override { if (framework::IsComplexType(expected_kernel_type.data_type_)) { // only promote inputs’s types when contains complex input return framework::OpKernelType( diff --git a/paddle/fluid/operators/elementwise/elementwise_mul_op.h b/paddle/fluid/operators/elementwise/elementwise_mul_op.h index 23271352f6b..c7b872af75a 100644 --- a/paddle/fluid/operators/elementwise/elementwise_mul_op.h +++ b/paddle/fluid/operators/elementwise/elementwise_mul_op.h @@ -38,7 +38,7 @@ class ElementwiseMulOp : public ElementwiseOp { framework::OpKernelType GetKernelTypeForVar( const std::string& var_name, const phi::DenseTensor& tensor, - const framework::OpKernelType& expected_kernel_type) const { + const framework::OpKernelType& expected_kernel_type) const override { if (framework::IsComplexType(expected_kernel_type.data_type_)) { // only promote inputs’s types when contains complex input return framework::OpKernelType( diff --git a/paddle/fluid/operators/elementwise/elementwise_op.h b/paddle/fluid/operators/elementwise/elementwise_op.h index 35008ec6012..c6b47d5d979 100644 --- a/paddle/fluid/operators/elementwise/elementwise_op.h +++ b/paddle/fluid/operators/elementwise/elementwise_op.h @@ -357,7 +357,7 @@ class ElementwiseOpDoubleGrad : public framework::OperatorWithKernel { framework::OpKernelType GetKernelTypeForVar( const std::string &var_name, const phi::DenseTensor &tensor, - const framework::OpKernelType &expected_kernel_type) const { + const framework::OpKernelType &expected_kernel_type) const override { if (framework::IsComplexType(expected_kernel_type.data_type_)) { // only promote inputs’s types when contains complex input return framework::OpKernelType( @@ -409,7 +409,7 @@ class ElementwiseOpDoubleGradWithoutDXDY framework::OpKernelType GetKernelTypeForVar( const std::string &var_name, const phi::DenseTensor &tensor, - const framework::OpKernelType &expected_kernel_type) const { + const framework::OpKernelType &expected_kernel_type) const override { if (framework::IsComplexType(expected_kernel_type.data_type_)) { // only promote inputs’s types when contains complex input return framework::OpKernelType( @@ -461,7 +461,7 @@ class ElementwiseOpTripleGrad : public framework::OperatorWithKernel { framework::OpKernelType GetKernelTypeForVar( const std::string &var_name, const phi::DenseTensor &tensor, - const framework::OpKernelType &expected_kernel_type) const { + const framework::OpKernelType &expected_kernel_type) const override { if (framework::IsComplexType(expected_kernel_type.data_type_)) { // only promote inputs’s types when contains complex input return framework::OpKernelType( diff --git a/paddle/fluid/operators/inplace_abn_op.cc b/paddle/fluid/operators/inplace_abn_op.cc index 53b7ba51b22..110a0bf105e 100644 --- a/paddle/fluid/operators/inplace_abn_op.cc +++ b/paddle/fluid/operators/inplace_abn_op.cc @@ -73,7 +73,7 @@ class InplaceABNGradOp : public paddle::operators::BatchNormGradOp { public: using paddle::operators::BatchNormGradOp::BatchNormGradOp; - void InferShape(framework::InferShapeContext* ctx) const { + void InferShape(framework::InferShapeContext* ctx) const override { // check input OP_INOUT_CHECK(ctx->HasInput("Scale"), "Input", "Scale", "InplaceABNGrad"); OP_INOUT_CHECK(ctx->HasInput(framework::GradVarName("Y")), diff --git a/paddle/fluid/operators/optimizers/sgd_op.cc b/paddle/fluid/operators/optimizers/sgd_op.cc index d463c979353..099d35502c7 100644 --- a/paddle/fluid/operators/optimizers/sgd_op.cc +++ b/paddle/fluid/operators/optimizers/sgd_op.cc @@ -60,7 +60,7 @@ class SGDOp : public framework::OperatorWithKernel { framework::OpKernelType GetKernelTypeForVar( const std::string &var_name, const phi::DenseTensor &tensor, - const framework::OpKernelType &expected_kernel_type) const { + const framework::OpKernelType &expected_kernel_type) const override { if (var_name == "LearningRate") { return framework::OpKernelType( framework::TransToProtoVarType(tensor.dtype()), diff --git a/paddle/fluid/operators/pad2d_op.cc b/paddle/fluid/operators/pad2d_op.cc index c750a76ce10..4d8e140c013 100644 --- a/paddle/fluid/operators/pad2d_op.cc +++ b/paddle/fluid/operators/pad2d_op.cc @@ -718,7 +718,7 @@ class Pad2dOp : public framework::OperatorWithKernel { framework::OpKernelType GetKernelTypeForVar( const std::string& var_name, const phi::DenseTensor& tensor, - const framework::OpKernelType& expected_kernel_type) const { + const framework::OpKernelType& expected_kernel_type) const override { #ifdef PADDLE_WITH_MKLDNN if ((expected_kernel_type.data_layout_ == phi::DataLayout::kMKLDNN) && (tensor.layout() != phi::DataLayout::kMKLDNN)) { -- GitLab