1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00

Coding - Initialize member variables with default values #362

Clang-tidy applying rule for cppcoreguidelines-pro-type-member-init.
Updated: TKernel and TKMath
Update constructor in some classes instead of direct initialization
Refactor Bnd_BoundSortBox and Bnd_Box constructors to initialize member variables directly
This commit is contained in:
Pasukhin Dmitry 2025-02-12 15:26:00 +01:00 committed by GitHub
parent a8950426b5
commit fb73c3b712
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 120 additions and 77 deletions

View File

@ -64,7 +64,7 @@ public:
private:
// local buffer, to be sufficient for addressing by index [Degree+1][Degree+1]
// (see math_Matrix implementation)
Standard_Real myBuffer[27 * 27];
Standard_Real myBuffer[27 * 27]{};
};
//=================================================================================================

View File

@ -46,9 +46,9 @@ struct BSplCLib_DataContainer
"BSplCLib: bspline degree is greater than maximum supported");
}
Standard_Real poles[2 * (25 + 1)];
Standard_Real knots[2 * 25];
Standard_Real ders[4];
Standard_Real poles[2 * (25 + 1)]{};
Standard_Real knots[2 * 25]{};
Standard_Real ders[4]{};
};
// methods for 1 dimensional BSplines

View File

@ -54,10 +54,10 @@ struct BSplSLib_DataContainer
"BSplSLib: bspline degree is greater than maximum supported");
}
Standard_Real poles[4 * (25 + 1) * (25 + 1)];
Standard_Real knots1[2 * 25];
Standard_Real knots2[2 * 25];
Standard_Real ders[48];
Standard_Real poles[4 * (25 + 1) * (25 + 1)]{};
Standard_Real knots1[2 * 25]{};
Standard_Real knots2[2 * 25]{};
Standard_Real ders[48]{};
};
//**************************************************************************

View File

@ -418,15 +418,25 @@ void BSB_T3Bits::AppendAxisX(const Standard_Integer i, const Standard_Integer v)
axisX[0][i] = n;
}
//=======================================================================
//=================================================================================================
Bnd_BoundSortBox::Bnd_BoundSortBox()
: discrX(0),
: myBox(),
myBndComponents(nullptr),
Xmin(0.),
Ymin(0.),
Zmin(0.),
deltaX(0.),
deltaY(0.),
deltaZ(0.),
discrX(0),
discrY(0),
discrZ(0)
discrZ(0),
theFound(0),
Crible(),
lastResult(),
TabBits(0)
{
TabBits = 0;
#if DEBUG
NBCOMPARE = 0L;
NBBOITES = 0L;

View File

@ -32,24 +32,31 @@
//=================================================================================================
Bnd_Box::Bnd_Box()
// Equal to SetVoid();
: Xmin(RealLast()),
Xmax(-RealLast()),
Ymin(RealLast()),
Ymax(-RealLast()),
Zmin(RealLast()),
Zmax(-RealLast()),
Gap(0.0)
Gap(0.0),
Flags(VoidMask)
{
SetVoid();
}
//=================================================================================================
Bnd_Box::Bnd_Box(const gp_Pnt& theMin, const gp_Pnt& theMax)
: Gap(0.0)
// Equal to Update(theMin.X(), theMin.Y(), theMin.Z(), theMax.X(), theMax.Y(), theMax.Z());
: Xmin(theMin.X()),
Xmax(theMax.X()),
Ymin(theMin.Y()),
Ymax(theMax.Y()),
Zmin(theMin.Z()),
Zmax(theMax.Z()),
Gap(0.0),
Flags(0)
{
SetVoid();
Update(theMin.X(), theMin.Y(), theMin.Z(), theMax.X(), theMax.Y(), theMax.Z());
}
//=================================================================================================

View File

@ -83,8 +83,8 @@ public:
Ymax = -RealLast();
Zmin = RealLast();
Zmax = -RealLast();
Flags = VoidMask;
Gap = 0.0;
Flags = VoidMask;
}
//! Sets this bounding box so that it bounds

View File

@ -358,7 +358,7 @@ private:
//! Points of ditetrahedron
//! given by their indices in myLExtremalPoints.
Standard_Integer myTriIdx[5];
Standard_Integer myTriIdx[5]{};
//! List of extremal points
gp_XYZ myLExtremalPoints[myNbExtremalPoints];

View File

@ -93,13 +93,13 @@ private:
const CSLib_Class2d& operator=(const CSLib_Class2d& Other) const;
NCollection_Handle<TColStd_Array1OfReal> MyPnts2dX, MyPnts2dY;
Standard_Real Tolu;
Standard_Real Tolv;
Standard_Integer N;
Standard_Real Umin;
Standard_Real Vmin;
Standard_Real Umax;
Standard_Real Vmax;
Standard_Real Tolu{};
Standard_Real Tolv{};
Standard_Integer N{};
Standard_Real Umin{};
Standard_Real Vmin{};
Standard_Real Umax{};
Standard_Real Vmax{};
};
#endif // _CSLib_Class2d_HeaderFile

View File

@ -26,7 +26,8 @@
Convert_CompBezierCurves2dToBSplineCurve2d::Convert_CompBezierCurves2dToBSplineCurve2d(
const Standard_Real AngularTolerance)
: myAngular(AngularTolerance),
: myDegree(0),
myAngular(AngularTolerance),
myDone(Standard_False)
{
}

View File

@ -26,7 +26,8 @@
Convert_CompBezierCurvesToBSplineCurve::Convert_CompBezierCurvesToBSplineCurve(
const Standard_Real AngularTolerance)
: myAngular(AngularTolerance),
: myDegree(0),
myAngular(AngularTolerance),
myDone(Standard_False)
{
}

View File

@ -39,7 +39,8 @@ Convert_ConicToBSplineCurve::Convert_ConicToBSplineCurve(const Standard_Integer
const Standard_Integer Degree)
: degree(Degree),
nbPoles(NbPoles),
nbKnots(NbKnots)
nbKnots(NbKnots),
isperiodic(Standard_False)
{
if (NbPoles >= 2)

View File

@ -38,7 +38,9 @@ Convert_ElementarySurfaceToBSplineSurface::Convert_ElementarySurfaceToBSplineSur
nbUPoles(NbUPoles),
nbVPoles(NbVPoles),
nbUKnots(NbUKnots),
nbVKnots(NbVKnots)
nbVKnots(NbVKnots),
isuperiodic(Standard_False),
isvperiodic(Standard_False)
{
}

View File

@ -456,7 +456,7 @@ Storage_Error FSD_BinaryFile::BeginWriteInfoSection()
union {
char ti2[4];
Standard_Integer aResult;
} aWrapUnion;
} aWrapUnion{};
aWrapUnion.ti2[0] = 1;
aWrapUnion.ti2[1] = 2;
@ -619,7 +619,7 @@ void FSD_BinaryFile::ReadInfo(Standard_Integer& nbObj,
void FSD_BinaryFile::ReadCompleteInfo(Standard_IStream& theIStream, Handle(Storage_Data)& theData)
{
FSD_FileHeader aHeaderPos;
FSD_FileHeader aHeaderPos{};
ReadHeader(theIStream, aHeaderPos);
if (theData.IsNull())
@ -1678,7 +1678,7 @@ Standard_Real FSD_BinaryFile::InverseReal(const Standard_Real theValue)
union {
Standard_Integer i[2];
Standard_Real aValue;
} aWrapUnion;
} aWrapUnion{};
aWrapUnion.aValue = theValue;
@ -1701,7 +1701,7 @@ Standard_ShortReal FSD_BinaryFile::InverseShortReal(const Standard_ShortReal the
union {
Standard_ShortReal aValue;
Standard_Integer aResult;
} aWrapUnion;
} aWrapUnion{};
aWrapUnion.aValue = theValue;
aWrapUnion.aResult = InverseInt(aWrapUnion.aResult);
@ -1729,7 +1729,7 @@ inline uint64_t OCCT_InverseSizeSpecialized<8>(const uint64_t theValue, int)
union {
Standard_Integer i[2];
uint64_t aValue;
} aWrapUnion;
} aWrapUnion{};
aWrapUnion.aValue = theValue;

View File

@ -372,7 +372,7 @@ private:
private:
FSD_BStream myStream;
FSD_FileHeader myHeader;
FSD_FileHeader myHeader{};
};
#endif // _FSD_BinaryFile_HeaderFile

View File

@ -86,7 +86,7 @@ void* NCollection_AccAllocator::Allocate(const size_t theSize)
//=======================================================================
void NCollection_AccAllocator::Free(void* theAddress)
{
Key aKey;
Key aKey{};
Block* aBlock = findBlock(theAddress, aKey);
#if !defined No_Exception && !defined No_Standard_ProgramError

View File

@ -56,7 +56,7 @@ void OSD_Chronometer::GetProcessCPU(Standard_Real& theUserSeconds, Standard_Real
static const long aCLK_TCK = CLK_TCK;
#endif
tms aCurrentTMS;
tms aCurrentTMS{};
times(&aCurrentTMS);
theUserSeconds = (Standard_Real)aCurrentTMS.tms_utime / aCLK_TCK;

View File

@ -61,7 +61,7 @@ private:
TCollection_AsciiString myMessage;
Standard_Integer myErrno;
OSD_WhoAmI myCode;
Standard_Integer extCode;
Standard_Integer extCode{};
};
#endif // _OSD_Error_HeaderFile

View File

@ -150,10 +150,10 @@ private:
// ---------- PRIVATE FIELDS ----------
Standard_Integer myNConnections;
Standard_Integer myNodes[3];
Standard_Integer myNodesOnConnected[3];
const Poly_CoherentTriangle* mypConnected[3];
const Poly_CoherentLink* mypLink[3];
Standard_Integer myNodes[3]{};
Standard_Integer myNodesOnConnected[3]{};
const Poly_CoherentTriangle* mypConnected[3]{};
const Poly_CoherentLink* mypLink[3]{};
friend class Poly_CoherentTriangulation;
};

View File

@ -108,6 +108,8 @@ Quantity_Date::Quantity_Date(const Standard_Integer mm,
const Standard_Integer ss,
const Standard_Integer mis,
const Standard_Integer mics)
: mySec(0),
myUSec(0)
{
SetValues(mm, dd, yy, hh, mn, ss, mis, mics);

View File

@ -66,6 +66,8 @@ Quantity_Period::Quantity_Period(const Standard_Integer dd,
const Standard_Integer ss,
const Standard_Integer mils,
const Standard_Integer mics)
: mySec(0),
myUSec(0)
{
SetValues(dd, hh, mn, ss, mils, mics);
@ -77,6 +79,8 @@ Quantity_Period::Quantity_Period(const Standard_Integer dd,
//
// -------------------------------------------------------------
Quantity_Period::Quantity_Period(const Standard_Integer ss, const Standard_Integer mics)
: mySec(0),
myUSec(0)
{
SetValues(ss, mics);

View File

@ -135,7 +135,8 @@ Resource_Manager::Resource_Manager(const Standard_CString aName, const Standard_
Resource_Manager::Resource_Manager()
: myName(""),
myVerbose(Standard_False)
myVerbose(Standard_False),
myInitialized(Standard_False)
{
}

View File

@ -347,7 +347,7 @@ void Standard_GUID::ToExtString(const Standard_PExtCharacter aStrGuid) const
Standard_UUID Standard_GUID::ToUUID() const
{
Standard_UUID result;
Standard_UUID result{};
result.Data1 = my32b;
result.Data2 = my16b1;

View File

@ -145,7 +145,7 @@ union RealMap {
//--------------------------------------------------------------------
static int HardwareHighBitsOfDouble()
{
RealMap MaxDouble;
RealMap MaxDouble{};
MaxDouble.real = DBL_MAX;
//=========================================================
// representation of the max double in IEEE is
@ -170,7 +170,7 @@ static int HardwareHighBitsOfDouble()
//--------------------------------------------------------------------
static int HardwareLowBitsOfDouble()
{
RealMap MaxDouble;
RealMap MaxDouble{};
MaxDouble.real = DBL_MAX;
//=========================================================
// representation of the max double in IEEE is
@ -193,7 +193,7 @@ static const int LowBitsOfDouble = HardwareLowBitsOfDouble();
double NextAfter(const double x, const double y)
{
RealMap res;
RealMap res{};
res.real = x;

View File

@ -197,7 +197,7 @@ TCollection_ExtendedString::TCollection_ExtendedString(const Standard_Integer aV
union {
int bid;
char t[13];
} CHN;
} CHN{};
Sprintf(&CHN.t[0], "%d", aValue);
allocate((int)strlen(CHN.t));
@ -213,7 +213,7 @@ TCollection_ExtendedString::TCollection_ExtendedString(const Standard_Real aValu
union {
int bid;
char t[50];
} CHN;
} CHN{};
Sprintf(&CHN.t[0], "%g", aValue);
allocate((int)strlen(CHN.t));

View File

@ -110,9 +110,9 @@ public:
protected:
private:
Standard_Integer thecurrentquantity;
Standard_Integer thecurrentquantity{};
Handle(Units_QuantitiesSequence) thequantitiessequence;
Standard_Integer thecurrentunit;
Standard_Integer thecurrentunit{};
Handle(Units_UnitsSequence) theunitssequence;
Handle(TColStd_HSequenceOfInteger) theactiveunitssequence;
};

View File

@ -96,8 +96,8 @@ protected:
private:
Standard_Boolean Done;
Standard_Boolean InfiniteStatus;
Standard_Integer NbSol;
Standard_Real TheRoots[4];
Standard_Integer NbSol{};
Standard_Real TheRoots[4]{};
};
#include <math_DirectPolynomialRoots.lxx>

View File

@ -66,7 +66,7 @@ private:
Standard_EXPORT void Allocate();
Standard_Address Addr;
Standard_Real Buf[16];
Standard_Real Buf[16]{};
Standard_Boolean isAllocated;
Standard_Integer LowR;
Standard_Integer UppR;

View File

@ -88,7 +88,7 @@ protected:
private:
Standard_Boolean Done;
Standard_Real TheRoot;
Standard_Real TheError;
Standard_Real TheError{};
Standard_Real TheDerivative;
Standard_Integer NbIter;
};

View File

@ -65,11 +65,11 @@ public:
Standard_EXPORT void Dump(Standard_OStream& o) const;
protected:
Standard_Boolean Singular;
Standard_Boolean Singular{};
math_Matrix LU;
math_Matrix A2;
math_IntegerVector Index;
Standard_Real D;
Standard_Real D{};
private:
Standard_Boolean Done;

View File

@ -67,8 +67,8 @@ private:
const Standard_Real Upper,
const Standard_Integer Order);
Standard_Real Val;
Standard_Boolean Done;
Standard_Real Val{};
Standard_Boolean Done{};
};
#include <math_GaussSingleIntegration.lxx>

View File

@ -248,19 +248,19 @@ private:
// Algorithm data.
Standard_Real myZ;
Standard_Real myE1; // Border coefficient.
Standard_Real myE2; // Minimum step size.
Standard_Real myE3; // Local extrema starting parameter.
Standard_Real myE1{}; // Border coefficient.
Standard_Real myE2{}; // Minimum step size.
Standard_Real myE3{}; // Local extrema starting parameter.
math_Vector myX; // Current modified solution.
math_Vector myTmp; // Current modified solution.
math_Vector myV; // Steps array.
math_Vector myMaxV; // Max Steps array.
Standard_Real myLastStep; // Last step.
math_Vector myX; // Current modified solution.
math_Vector myTmp; // Current modified solution.
math_Vector myV; // Steps array.
math_Vector myMaxV; // Max Steps array.
Standard_Real myLastStep{}; // Last step.
NCollection_Array1<Standard_Real> myCellSize;
Standard_Integer myMinCellFilterSol;
Standard_Boolean isFirstCellFilterInvoke;
Standard_Boolean isFirstCellFilterInvoke{};
NCollection_CellFilter<NCollection_CellFilter_Inspector> myFilter;
// Continuity of local borders.

View File

@ -39,7 +39,8 @@ math_Householder::math_Householder(const math_Matrix& A,
const math_Vector& B,
const Standard_Real EPS)
: Sol(1, A.ColNumber(), 1, 1),
Q(1, A.RowNumber(), 1, A.ColNumber())
Q(1, A.RowNumber(), 1, A.ColNumber()),
Done(Standard_False)
{
mylowerArow = A.LowerRow();
@ -55,7 +56,8 @@ math_Householder::math_Householder(const math_Matrix& A,
const math_Matrix& B,
const Standard_Real EPS)
: Sol(1, A.ColNumber(), 1, B.ColNumber()),
Q(1, A.RowNumber(), A.LowerCol(), A.UpperCol())
Q(1, A.RowNumber(), A.LowerCol(), A.UpperCol()),
Done(Standard_False)
{
mylowerArow = A.LowerRow();
@ -73,7 +75,8 @@ math_Householder::math_Householder(const math_Matrix& A,
const Standard_Integer upperAcol,
const Standard_Real EPS)
: Sol(1, upperAcol - lowerAcol + 1, 1, B.ColNumber()),
Q(1, upperArow - lowerArow + 1, 1, upperAcol - lowerAcol + 1)
Q(1, upperArow - lowerArow + 1, 1, upperAcol - lowerAcol + 1),
Done(Standard_False)
{
mylowerArow = lowerArow;
myupperArow = upperArow;

View File

@ -25,7 +25,9 @@
#include <math_Recipes.hxx>
math_Jacobi::math_Jacobi(const math_Matrix& A)
: AA(1, A.RowNumber(), 1, A.RowNumber()),
: Done(Standard_False),
AA(1, A.RowNumber(), 1, A.RowNumber()),
NbRotations(0),
EigenValues(1, A.RowNumber()),
EigenVectors(1, A.RowNumber(), 1, A.RowNumber())
{

View File

@ -26,6 +26,7 @@ math_KronrodSingleIntegration::math_KronrodSingleIntegration()
: myIsDone(Standard_False),
myValue(0.),
myErrorReached(0.),
myAbsolutError(0.),
myNbPntsReached(0),
myNbIterReached(0)
{
@ -43,7 +44,9 @@ math_KronrodSingleIntegration::math_KronrodSingleIntegration(math_Function&
: myIsDone(Standard_False),
myValue(0.),
myErrorReached(0.),
myNbPntsReached(0)
myAbsolutError(0.),
myNbPntsReached(0),
myNbIterReached(0)
{
Perform(theFunction, theLower, theUpper, theNbPnts);
}
@ -62,7 +65,9 @@ math_KronrodSingleIntegration::math_KronrodSingleIntegration(math_Function&
: myIsDone(Standard_False),
myValue(0.),
myErrorReached(0.),
myNbPntsReached(0)
myAbsolutError(0.),
myNbPntsReached(0),
myNbIterReached(0)
{
Perform(theFunction, theLower, theUpper, theNbPnts, theTolerance, theMaxNbIter);
}

View File

@ -46,7 +46,9 @@ math_Uzawa::math_Uzawa(const math_Matrix& Cont,
Erruza(1, Cont.ColNumber()),
Errinit(1, Cont.ColNumber()),
Vardua(1, Cont.RowNumber()),
CTCinv(1, Cont.RowNumber(), 1, Cont.RowNumber())
CTCinv(1, Cont.RowNumber(), 1, Cont.RowNumber()),
NbIter(0),
Done(Standard_False)
{
Perform(Cont, Secont, StartingPoint, Cont.RowNumber(), 0, EpsLix, EpsLic, NbIterations);
@ -64,7 +66,9 @@ math_Uzawa::math_Uzawa(const math_Matrix& Cont,
Erruza(1, Cont.ColNumber()),
Errinit(1, Cont.ColNumber()),
Vardua(1, Cont.RowNumber()),
CTCinv(1, Cont.RowNumber(), 1, Cont.RowNumber())
CTCinv(1, Cont.RowNumber(), 1, Cont.RowNumber()),
NbIter(0),
Done(Standard_False)
{
Perform(Cont, Secont, StartingPoint, Nce, Nci, EpsLix, EpsLic, NbIterations);