Archived issue #0025622
CAST analysis: Avoid invocation of virtual Methods of the declared Class in a Constructor or Destructor
Description
Invoking virtual Methods in a constructor always invokes the Method for the current Class, or its base, even when the constructor is invoked as part of the construction of a derived Class. This also applies to virtual Methods called in a Destructor.
Steps to reproduce
not applicable
Additional information
This problem is connected to cdl-mechanism. Virtual methods Delete() or Destroy() are called in Destructors of following classes:
- Adaptor2d_Curve2d
- Adaptor3d_Curve
- Adaptor3d_Surface
- AppBlend_Approx
- AppCont_Function
- AppParCurves_MultiCurve
- AppParCurves_MultiPoint
- ApproxInt_SvSurfaces
- BRepPrim_OneAxis
- BRepSweep_NumLinearRegularSweep
- CDM_Document (Destroy method)
- DBC_BaseArray
- GeomFill_Profiler
- Graphic3d_DataStructureManager (Destroy method)
- HatchGen_PointOnHatching
- Interface_CopyTool (Destroy method)
- math_BFGS
- math_FunctionSet
- math_FunctionSetRoot
- math_FunctionWithDerivative
- math_MultipleVarFunctionWithGradient
- OSD_Chronometer (Destroy method)
- ProjLib_Projector
- PrsMgr_Presentation (Destroy method)
It is necessary to move functionality of these methods in Destructors and remove them.
See: #0025619
- Adaptor2d_Curve2d
- Adaptor3d_Curve
- Adaptor3d_Surface
- AppBlend_Approx
- AppCont_Function
- AppParCurves_MultiCurve
- AppParCurves_MultiPoint
- ApproxInt_SvSurfaces
- BRepPrim_OneAxis
- BRepSweep_NumLinearRegularSweep
- CDM_Document (Destroy method)
- DBC_BaseArray
- GeomFill_Profiler
- Graphic3d_DataStructureManager (Destroy method)
- HatchGen_PointOnHatching
- Interface_CopyTool (Destroy method)
- math_BFGS
- math_FunctionSet
- math_FunctionSetRoot
- math_FunctionWithDerivative
- math_MultipleVarFunctionWithGradient
- OSD_Chronometer (Destroy method)
- ProjLib_Projector
- PrsMgr_Presentation (Destroy method)
It is necessary to move functionality of these methods in Destructors and remove them.
See: #0025619
Public activity
9 archived notes
Participants are labeled by their role within this record.
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Thu Dec 18 10:27:01 2014 +0300
0025622: CAST analysis: Avoid invocation of virtual Methods of the declared Class in a Constructor or Destructor
Virtual methods Delete() or Destroy() have been deleted in Destructors.
Classes Graphic3d_DataStructureManager and PrsMgr_Presentation without changes.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Thu Dec 18 10:27:01 2014 +0300
0025622: CAST analysis: Avoid invocation of virtual Methods of the declared Class in a Constructor or Destructor
Virtual methods Delete() or Destroy() have been deleted in Destructors.
Classes Graphic3d_DataStructureManager and PrsMgr_Presentation without changes.
Some remarks:
1. I suggest that empty destructors should be removed from classes whose base class already has virtual destructor:
math_MultipleVarFunctionWithHessian
math_MultipleVarFunctionWithGradient
math_FunctionWithDerivative
HatchGen_PointOnHatching
BRepSweep_Translation
BRepSweep_Trsf
2. There are many (~ 120) other classes not listed in description of this class (and not affected by the patch) that use the same approach to defining destructor via declaration of method Destroy() and using CDL alias to define destructor via that function. See e.g. XCAFDoc_DocumentTool. These classes should be addressed, too.
I suggest that this issue can address classes not inheriting Transient, while separate issue should be registered to eliminate method Destroy() in Transient and its descendants. Note that change in CDM_Document included in the current patch should be moved to that new issue.
1. I suggest that empty destructors should be removed from classes whose base class already has virtual destructor:
math_MultipleVarFunctionWithHessian
math_MultipleVarFunctionWithGradient
math_FunctionWithDerivative
HatchGen_PointOnHatching
BRepSweep_Translation
BRepSweep_Trsf
2. There are many (~ 120) other classes not listed in description of this class (and not affected by the patch) that use the same approach to defining destructor via declaration of method Destroy() and using CDL alias to define destructor via that function. See e.g. XCAFDoc_DocumentTool. These classes should be addressed, too.
I suggest that this issue can address classes not inheriting Transient, while separate issue should be registered to eliminate method Destroy() in Transient and its descendants. Note that change in CDM_Document included in the current patch should be moved to that new issue.
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
1. The above described classes have been fixed.
2. New issue #0025725 for Transient inheritors has been registered.
Please review.
2. New issue #0025725 for Transient inheritors has been registered.
Please review.
Reviewed, please test
Branch [archived branch] has been updated forcibly by Commenter 3.
[revision removed]
[revision removed]
Dear Commenter 1,
Branch CR25622 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested in Release mode.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 18 (18 on master)
Windows: 0 (0 on master)
products component :
Linux: 11 (11 on master)
Windows: 1 (1 on master)
Regressions/Differences:
No regressions
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 369349344 / 370125320
Total CPU difference: 53429.45000000009 / 51750.87000000009
Testing on Windows:
Total MEMORY difference: 275356424 / 275769192
Total CPU difference: 37036.359375 / 38148.296875
There are not differences in images found by testdiff.
Branch CR25622 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested in Release mode.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 18 (18 on master)
Windows: 0 (0 on master)
products component :
Linux: 11 (11 on master)
Windows: 1 (1 on master)
Regressions/Differences:
No regressions
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 369349344 / 370125320
Total CPU difference: 53429.45000000009 / 51750.87000000009
Testing on Windows:
Total MEMORY difference: 275356424 / 275769192
Total CPU difference: 37036.359375 / 38148.296875
There are not differences in images found by testdiff.
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Related records
- #0025577 · has duplicate · closedAvoid invocation of virtual Methods of the declared Class in a Constructor or Destructor
- #0025720 · related to · closedIncorrect code of math classes can lead to unpredicted behavior of algorithms
- #0025725 · related to · newAvoid invocation of virtual methods in constructors and destructors
- #0027067 · related to · closedAvoid use of virtual methods for implementation of destructors in legacy classes