Skip to content

Commit

Permalink
STYLE: Use override statements for C++11
Browse files Browse the repository at this point in the history
Describe function overrides using the override keyword from C++11.

-----
https://stackoverflow.com/questions/39932391/virtual-override-or-both-c
When you override a function you don't technically need to write either virtual
or override.

The original base class declaration needs the keyword virtual to mark it as
virtual.

In the derived class the function is virtual by way of having the ¹same type as
the base class function.

However, an override can help avoid bugs by producing a compilation error when
the intended override isn't technically an override. For instance, the function
type isn't exactly like the base class function. Or that a maintenance of the
base class changes that function's type, e.g. adding a defaulted argument.

In the same way, a virtual keyword in the derived class can make such a bug
more subtle by ensuring that the function is still virtual in the further
derived classes.

So the general advice is,

Use virtual for the base class function declaration.  This is technically
necessary.

Use override (only) for a derived class' override.  This helps maintenance.
-----

Remove 'virtual' is implied when 'override' is specified, so remove the
redundant specification.

cd ${BLDDIR}
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-use-override  -header-filter=.* -fix
  • Loading branch information
hjmjohnson committed Dec 22, 2024
1 parent ac77fef commit b06c36a
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkPyCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ITKCommon_EXPORT PyCommand : public Command

protected:
PyCommand();
~PyCommand();
~PyCommand() override;
void
PyExecute();
PyCommand(const Self &); // Not implemented.
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkPyImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ITK_TEMPLATE_EXPORT PyImageFilter : public ImageToImageFilter<TInputImage,

protected:
PyImageFilter();
virtual ~PyImageFilter();
~PyImageFilter() override;

void
GenerateInputRequestedRegion() override;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/SpatialObjects/include/itkTubeSpatialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ITK_TEMPLATE_EXPORT TubeSpatialObject : public PointBasedSpatialObject<TDi
void
PrintSelf(std::ostream & os, Indent indent) const override;

virtual typename LightObject::Pointer
typename LightObject::Pointer
InternalClone() const override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class ITK_TEMPLATE_EXPORT FastMarchingUpwindGradientImageFilter : public FastMar
void
PrintSelf(std::ostream & os, Indent indent) const override;

virtual void
void
VerifyPreconditions() const override;

void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ITK_TEMPLATE_EXPORT TernaryAddImageFilter
Superclass::SetFunctor(FunctorType());
#endif
}
virtual ~TernaryAddImageFilter() = default;
~TernaryAddImageFilter() override = default;
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class ITK_TEMPLATE_EXPORT DiscreteCurvatureTensorQuadEdgeMeshFilter

protected:
DiscreteCurvatureTensorQuadEdgeMeshFilter() = default;
~DiscreteCurvatureTensorQuadEdgeMeshFilter() = default;
~DiscreteCurvatureTensorQuadEdgeMeshFilter() override = default;

/// TODO to be implemented
virtual void
GenerateData()
void
GenerateData() override
{}
};
} // namespace itk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class ITK_TEMPLATE_EXPORT IntrinsicMatrixCoefficients : public MatrixCoefficient
{}

InputCoordinateType
operator()(const InputMeshType * iMesh, InputQEType * iEdge) const
operator()(const InputMeshType * iMesh, InputQEType * iEdge) const override
{
const AuthalicMatrixCoefficients<TInputMesh> authalic;
const ConformalMatrixCoefficients<TInputMesh> conformal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class ITK_TEMPLATE_EXPORT LBFGS2Optimizerv4Template
void
ResumeOptimization() override;

virtual StopConditionReturnStringType
StopConditionReturnStringType
GetStopConditionDescription() const override;

/**
Expand Down

0 comments on commit b06c36a

Please sign in to comment.