Skip to content

Commit

Permalink
STYLE: Add in-class {} member initializers to objects created by New()
Browse files Browse the repository at this point in the history
For an object created by `New()`, the performance cost of adding a `{}` default
member initializer to each of its non-static data members should be neglectable
compared to the cost of allocating the object itself, as it is allocated on the
heap.

In-class default member initialization effectively prevents Valgrind/Memcheck
warnings like "Conditional jump or move depends on uninitialised value(s)", and
Visual C++ Code Analysis warnings like "warning C26495: Variable is
uninitialized. Always initialize a member variable (type.6)"

These cases are found using the regular expression `  \w.* m_\w[^{}=]+;`,
excluding `static` data members and data members of a reference (`&`) type.

`Octree::m_ColorTable` was excluded, to avoid GCC warnings saying "const/copy
propagation disabled" and "GCSE disabled" [-Wdisabled-optimization].
  • Loading branch information
N-Dekker authored and dzenanz committed Jan 19, 2023
1 parent d2ff311 commit 5e2c49f
Show file tree
Hide file tree
Showing 805 changed files with 3,211 additions and 3,211 deletions.
16 changes: 8 additions & 8 deletions Modules/Bridge/VTK/include/itkVTKImageExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ class ITK_TEMPLATE_EXPORT VTKImageExport : public VTKImageExportBase
BufferPointerCallback() override;

private:
std::string m_ScalarTypeName;
int m_WholeExtent[6];
int m_DataExtent[6];
double m_DataSpacing[3];
double m_DataOrigin[3];
double m_DataDirection[9];
float m_FloatDataSpacing[3];
float m_FloatDataOrigin[3];
std::string m_ScalarTypeName{};
int m_WholeExtent[6]{};
int m_DataExtent[6]{};
double m_DataSpacing[3]{};
double m_DataOrigin[3]{};
double m_DataDirection[9]{};
float m_FloatDataSpacing[3]{};
float m_FloatDataOrigin[3]{};
};
} // end namespace itk

Expand Down
2 changes: 1 addition & 1 deletion Modules/Bridge/VTK/include/itkVTKImageImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ITK_TEMPLATE_EXPORT VTKImageImport : public ImageSource<TOutputImage>
DataExtentCallbackType m_DataExtentCallback{ nullptr };
BufferPointerCallbackType m_BufferPointerCallback{ nullptr };

std::string m_ScalarTypeName;
std::string m_ScalarTypeName{};
};
} // namespace itk

Expand Down
4 changes: 2 additions & 2 deletions Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class ITK_TEMPLATE_EXPORT ImageToVTKImageFilter : public ProcessObject
~ImageToVTKImageFilter() override;

private:
ExporterFilterPointer m_Exporter;
vtkImageImport * m_Importer;
ExporterFilterPointer m_Exporter{};
vtkImageImport * m_Importer{};
};

} // end namespace itk
Expand Down
2 changes: 1 addition & 1 deletion Modules/Bridge/VtkGlue/include/itkVTKImageToImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ITK_TEMPLATE_EXPORT VTKImageToImageFilter : public VTKImageImport<TOutputI

private:
using ImageExportPointer = vtkSmartPointer<vtkImageExport>;
ImageExportPointer m_Exporter;
ImageExportPointer m_Exporter{};
};

} // end namespace itk
Expand Down
4 changes: 2 additions & 2 deletions Modules/Compatibility/Deprecated/include/itkBarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class ITKDeprecated_EXPORT Barrier : public LightObject
unsigned int m_NumberArrived{ 0 };
unsigned int m_NumberExpected{ 0 };
unsigned int m_Generation{ 0 }; // Allows successive waits
std::condition_variable m_ConditionVariable;
std::mutex m_Mutex;
std::condition_variable m_ConditionVariable{};
std::mutex m_Mutex{};
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ITKDeprecated_EXPORT ConditionVariable : public LightObject
~ConditionVariable() override;

private:
ConditionVariableType m_ConditionVariable;
ConditionVariableType m_ConditionVariable{};
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ITKDeprecated_EXPORT FastMutexLock : public Object
FastMutexLock() = default;
~FastMutexLock() override = default;

SimpleFastMutexLock m_SimpleFastMutexLock;
SimpleFastMutexLock m_SimpleFastMutexLock{};
void
PrintSelf(std::ostream & os, Indent indent) const override;
};
Expand Down
2 changes: 1 addition & 1 deletion Modules/Compatibility/Deprecated/include/itkMutexLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ITKDeprecated_EXPORT MutexLock : public Object
MutexLock() = default;
~MutexLock() override = default;

SimpleMutexLock m_SimpleMutexLock;
SimpleMutexLock m_SimpleMutexLock{};
void
PrintSelf(std::ostream & os, Indent indent) const override;
};
Expand Down
4 changes: 2 additions & 2 deletions Modules/Compatibility/Deprecated/include/itkTreeContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ class ITK_TEMPLATE_EXPORT TreeContainer : public TreeContainerBase<TValue>
TreeContainer();
~TreeContainer() override = default;

typename TreeNodeType::Pointer m_Root;
typename TreeNodeType::Pointer m_Root{};

int m_DefaultChildrenCount;
int m_DefaultChildrenCount{};

void
PrintSelf(std::ostream & os, Indent indent) const override;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Compatibility/Deprecated/include/itkTreeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ class ITK_TEMPLATE_EXPORT TreeNode : public Object
TreeNode() = default;
~TreeNode() override;

TValue m_Data;
TValue m_Data{};
Self * m_Parent{ nullptr };

ChildrenListType m_Children;
ChildrenListType m_Children{};
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ITK_TEMPLATE_EXPORT VectorCentralDifferenceImageFunction
private:
// flag to take or not the image direction into account
// when computing the derivatives.
bool m_UseImageDirection;
bool m_UseImageDirection{};
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ class ITK_TEMPLATE_EXPORT VectorResampleImageFilter : public ImageToImageFilter<


private:
SizeType m_Size;
TransformPointerType m_Transform;
InterpolatorPointerType m_Interpolator;
PixelType m_DefaultPixelValue;
SpacingType m_OutputSpacing;
OriginPointType m_OutputOrigin;
DirectionType m_OutputDirection;
IndexType m_OutputStartIndex;
SizeType m_Size{};
TransformPointerType m_Transform{};
InterpolatorPointerType m_Interpolator{};
PixelType m_DefaultPixelValue{};
SpacingType m_OutputSpacing{};
OriginPointType m_OutputOrigin{};
DirectionType m_OutputDirection{};
IndexType m_OutputStartIndex{};
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ITK_TEMPLATE_EXPORT AutoPointerDataObjectDecorator : public DataObject

protected:
private:
ComponentPointer m_Component;
ComponentPointer m_Component{};
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ class ITK_TEMPLATE_EXPORT BinaryThresholdSpatialFunction
void
PrintSelf(std::ostream & os, Indent indent) const override;

FunctionOutputType m_LowerThreshold;
FunctionOutputType m_UpperThreshold;
FunctionOutputType m_LowerThreshold{};
FunctionOutputType m_UpperThreshold{};

typename FunctionType::Pointer m_Function;
typename FunctionType::Pointer m_Function{};
};
} // end namespace itk

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkBoundingBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ class ITK_TEMPLATE_EXPORT BoundingBox : public Object
using ConstIterator = typename PointsContainer::ConstIterator;

private:
PointsContainerConstPointer m_PointsContainer;
PointsContainerConstPointer m_PointsContainer{};
#if !defined(ITK_LEGACY_REMOVE)
PointsContainerPointer m_CornersContainer{ PointsContainer::New() };
#endif
mutable BoundsArrayType m_Bounds;
mutable BoundsArrayType m_Bounds{};
mutable TimeStamp m_BoundsMTime; // The last time the bounds
// were computed.
};
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkColorTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class ITK_TEMPLATE_EXPORT ColorTable : public Object

unsigned int m_NumberOfColors{ 0 };

ColorNameVectorType m_ColorName;
ColorVectorType m_Color;
ColorNameVectorType m_ColorName{};
ColorVectorType m_Color{};
};
} // namespace itk

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class ITKCommon_EXPORT FunctionCommand : public Command
~FunctionCommand() override;


FunctionObjectType m_FunctionObject;
FunctionObjectType m_FunctionObject{};
};

} // end namespace itk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class ITK_TEMPLATE_EXPORT ConicShellInteriorExteriorSpatialFunction
PrintSelf(std::ostream & os, Indent indent) const override;

private:
InputType m_Origin;
GradientType m_OriginGradient;
InputType m_Origin{};
GradientType m_OriginGradient{};
double m_DistanceMin{ 0.0 };
double m_DistanceMax{ 0.0 };
double m_Epsilon{ 0.0 };
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkDataObjectDecorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ITK_TEMPLATE_EXPORT DataObjectDecorator : public DataObject

protected:
private:
ComponentPointer m_Component;
ComponentPointer m_Component{};
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class ITK_TEMPLATE_EXPORT EllipsoidInteriorExteriorSpatialFunction

private:
/** The center of the ellipsoid. */
InputType m_Center;
InputType m_Center{};

/** The axes lengths of the ellipsoid. */
InputType m_Axes;
InputType m_Axes{};

/** The orientation vectors (must be orthogonal) of the ellipsoid axes. */
OrientationType m_Orientations{};
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkEquivalencyTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class ITKCommon_EXPORT EquivalencyTable : public DataObject
void
PrintSelf(std::ostream & os, Indent indent) const override;

HashTableType m_HashMap;
HashTableType m_HashMap{};
};
} // end namespace itk

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkExtractImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ class ITK_TEMPLATE_EXPORT ExtractImageFilter : public InPlaceImageFilter<TInputI
void
GenerateData() override;

InputImageRegionType m_ExtractionRegion;
InputImageRegionType m_ExtractionRegion{};

OutputImageRegionType m_OutputImageRegion;
OutputImageRegionType m_OutputImageRegion{};

private:
DirectionCollapseStrategyEnum m_DirectionCollapseStrategy{ DirectionCollapseStrategyEnum::DIRECTIONCOLLAPSETOUNKOWN };
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkFileOutputWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class ITKCommon_EXPORT FileOutputWindow : public OutputWindow
void
Initialize();

std::ofstream * m_Stream;
std::ofstream * m_Stream{};

std::string m_FileName;
std::string m_FileName{};

bool m_Flush;
bool m_Append;
bool m_Flush{};
bool m_Append{};
};
} // end namespace itk

Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Common/include/itkFiniteCylinderSpatialFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ class ITK_TEMPLATE_EXPORT FiniteCylinderSpatialFunction : public InteriorExterio

private:
/** The center of the cylinder. */
InputType m_Center;
InputType m_Center{};

/** The medial axis length of the cylinder. */
double m_AxisLength;
double m_AxisLength{};

/** The radius length of the cylinder. */
double m_Radius;
double m_Radius{};

/** The orientation vectors (must be orthogonal) of the ellipsoid axes. */
InputType m_Orientation;
InputType m_NormalizedOrientation;
InputType m_Orientation{};
InputType m_NormalizedOrientation{};
};
} // end namespace itk

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkFrustumSpatialFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ITK_TEMPLATE_EXPORT FrustumSpatialFunction : public InteriorExteriorSpatia
PrintSelf(std::ostream & os, Indent indent) const override;

private:
InputType m_Apex;
InputType m_Apex{};
double m_AngleZ{ 0.0f };
double m_ApertureAngleX{ 0.0f };
double m_ApertureAngleY{ 0.0f };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ class ITK_TEMPLATE_EXPORT GaussianDerivativeSpatialFunction : public SpatialFunc

private:
/** Current direction */
mutable unsigned int m_Direction;
mutable unsigned int m_Direction{};

/** The standard deviation in each direction. */
ArrayType m_Sigma;
ArrayType m_Sigma{};

/** The mean in each direction. */
ArrayType m_Mean;
ArrayType m_Mean{};

/** A scale factor multiplied by the true value of the Gaussian. */
double m_Scale;
double m_Scale{};

/** Whether or not to normalize the Gaussian. */
bool m_Normalized;
bool m_Normalized{};
};
} // end namespace itk

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkGaussianKernelFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ITK_TEMPLATE_EXPORT GaussianKernelFunction : public KernelFunctionBase<TRe
}

private:
const TRealValueType m_Factor;
const TRealValueType m_Factor{};
};
} // end namespace itk

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkGaussianSpatialFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class ITK_TEMPLATE_EXPORT GaussianSpatialFunction : public SpatialFunction<TOutp
PrintSelf(std::ostream & os, Indent indent) const override;

private:
ArrayType m_Sigma;
ArrayType m_Sigma{};

ArrayType m_Mean;
ArrayType m_Mean{};

double m_Scale{ 1.0 };

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class ITK_TEMPLATE_EXPORT Image : public ImageBase<VImageDimension>

private:
/** Memory for the current buffer. */
PixelContainerPointer m_Buffer;
PixelContainerPointer m_Buffer{};
};
} // end namespace itk

Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkImageBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,9 @@ class ITK_TEMPLATE_EXPORT ImageBase : public DataObject
private:
OffsetValueType m_OffsetTable[VImageDimension + 1]{};

RegionType m_LargestPossibleRegion;
RegionType m_RequestedRegion;
RegionType m_BufferedRegion;
RegionType m_LargestPossibleRegion{};
RegionType m_RequestedRegion{};
RegionType m_BufferedRegion{};
};
} // end namespace itk

Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkImageDuplicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ class ITK_TEMPLATE_EXPORT ImageDuplicator : public Object
PrintSelf(std::ostream & os, Indent indent) const override;

private:
ImageConstPointer m_InputImage;
ImagePointer m_DuplicateImage;
ModifiedTimeType m_InternalImageTime;
ImageConstPointer m_InputImage{};
ImagePointer m_DuplicateImage{};
ModifiedTimeType m_InternalImageTime{};
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ITKCommon_EXPORT ImageRegionSplitterDirection : public ImageRegionSplitter
PrintSelf(std::ostream & os, Indent indent) const override;

private:
unsigned int m_Direction;
unsigned int m_Direction{};
};
} // end namespace itk

Expand Down
Loading

0 comments on commit 5e2c49f

Please sign in to comment.