Coding - Apply modernize-loop-convert for range-based for loops#1208
Open
jijinbei wants to merge 7 commits intoOpen-Cascade-SAS:IRfrom
Open
Coding - Apply modernize-loop-convert for range-based for loops#1208jijinbei wants to merge 7 commits intoOpen-Cascade-SAS:IRfrom
jijinbei wants to merge 7 commits intoOpen-Cascade-SAS:IRfrom
Conversation
Raw output from run-clang-tidy 20.1.8 with:
-checks='-*,modernize-loop-convert'
103 files changed. clang-tidy only converts loops over arrays,
STL-style containers with begin()/end(), and NCollection types that
expose STL iterators (List, DataMap, Map, Indexed{Data}Map, Array1,
Sequence). OCCT's More()/Next()/Value() iterator idiom is not
detected by this check and is left untouched.
Restore OCCT's formatting rules across the 73 files touched by modernize-loop-convert. The rewriter does not preserve column widths or spacing; this is a pure format pass, no semantic changes.
Ubuntu GCC CI (-Werror=unused-variable) caught one dangling variable left behind by the rewrite: Units_Lexicon.cxx computed the array length for the old for(i; i<N; ++i) loop; range-based for makes it unused.
clang-tidy loop-convert resolved 'size_t' to the concrete platform type 'unsigned long&' when emitting the range declaration. This compiles on Linux (where size_t = unsigned long) but breaks on Windows MSVC (size_t = unsigned __int64). Rewrite as 'auto&' so the loop is portable.
macOS Clang -Werror caught another unused-variable left by the range-for rewrite in AIS_ViewController.cxx (aNbKeys).
There was a problem hiding this comment.
Pull request overview
Applies clang-tidy modernize-loop-convert across src/ to replace eligible index/iterator loops with range-based for loops, followed by formatting.
Changes:
- Convert eligible container/array loops to range-based
for. - Keep OCCT
More()/Next()/Value()iterator patterns unchanged. - Apply clang-format to touched files.
Reviewed changes
Copilot reviewed 103 out of 103 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Visualization/TKV3d/V3d/V3d_View.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/V3d/V3d_Trihedron.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/SelectMgr/SelectMgr_ViewClipRange.hxx | Range-based loop conversion |
| src/Visualization/TKV3d/SelectMgr/SelectMgr_ViewClipRange.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/SelectMgr/SelectMgr_TriangularFrustumSet.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/SelectMgr/SelectMgr_TriangularFrustum.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/SelectMgr/SelectMgr_RectangularFrustum.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/SelectMgr/SelectMgr_Frustum.lxx | Range-based loop conversion |
| src/Visualization/TKV3d/Select3D/Select3D_SensitiveTriangulation.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/Prs3d/Prs3d_DatumAspect.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/Prs3d/Prs3d.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/AIS/AIS_ViewCube.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/AIS/AIS_ViewController.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/AIS/AIS_Trihedron.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/AIS/AIS_RubberBand.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/AIS/AIS_Manipulator.cxx | Range-based loop conversion |
| src/Visualization/TKV3d/AIS/AIS_LightSource.cxx | Range-based loop conversion |
| src/Visualization/TKService/Image/Image_Diff.cxx | Range-based loop conversion |
| src/Visualization/TKService/Graphic3d/Graphic3d_TransformPers.hxx | Range-based loop conversion |
| src/Visualization/TKService/Graphic3d/Graphic3d_FrameStatsData.cxx | Range-based loop conversion |
| src/Visualization/TKService/Graphic3d/Graphic3d_CubeMapSeparate.cxx | Range-based loop conversion |
| src/Visualization/TKService/Font/Font_FTFont.cxx | Range-based loop conversion |
| src/Visualization/TKService/Aspect/Aspect_XRSession.cxx | Range-based loop conversion |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_View.cxx | Range-based loop conversion |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_ShaderManager.cxx | Range-based loop conversion |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_SetOfShaderPrograms.hxx | Range-based loop conversion |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_SceneGeometry.hxx | Range-based loop conversion |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_SceneGeometry.cxx | Range-based loop conversion (incl. texture handle iteration) |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_GraduatedTrihedron.cxx | Range-based loop conversion |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_FrameStatsPrs.cxx | Range-based loop conversion |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_DepthPeeling.cxx | Range-based loop conversion |
| src/Visualization/TKOpenGl/OpenGl/OpenGl_Context.cxx | Range-based loop conversion (DumpJson) |
| src/Visualization/TKMeshVS/MeshVS/MeshVS_Tool.cxx | Range-based loop conversion |
| src/Visualization/TKMeshVS/MeshVS/MeshVS_SensitiveQuad.cxx | Range-based loop conversion |
| src/Visualization/TKMeshVS/MeshVS/MeshVS_NodalColorPrsBuilder.cxx | Range-based loop conversion |
| src/Visualization/TKMeshVS/MeshVS/MeshVS_ElementalColorPrsBuilder.cxx | Range-based loop conversion |
| src/ModelingData/TKGeomBase/GeomBndLib/GeomBndLib_SurfaceOfRevolution.cxx | Range-based loop conversion |
| src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPRevS.cxx | Range-based loop conversion |
| src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPExtS.cxx | Range-based loop conversion |
| src/ModelingData/TKGeomBase/Extrema/Extrema_ExtPElS.cxx | Range-based loop conversion |
| src/ModelingData/TKGeomBase/Extrema/Extrema_ExtElC2d.cxx | Range-based loop conversion |
| src/ModelingData/TKGeomBase/Extrema/Extrema_ExtElC.cxx | Range-based loop conversion |
| src/ModelingData/TKBRep/BRepTools/BRepTools_History.cxx | Range-based loop conversion |
| src/ModelingData/TKBRep/BRepGraph/BRepGraph_BuilderView.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKTopAlgo/BRepExtrema/BRepExtrema_OverlapTool.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKTopAlgo/BRepExtrema/BRepExtrema_DistanceSS.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKTopAlgo/BRepClass3d/BRepClass3d_SClassifier.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKPrim/BRepPrim/BRepPrim_GWedge.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKOffset/BiTgte/BiTgte_Blend.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKOffset/BRepOffset/BRepOffset_Tool.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKOffset/BRepOffset/BRepOffset_MakeOffset.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKOffset/BRepOffset/BRepOffset_Inter3d.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_SelectorOfDataStructureOfDelaun.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_MeshTool.hxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_MeshTool.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_GeomTool.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_Delaun.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_DataStructureOfDelaun.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKMesh/BRepMesh/BRepMesh_BaseMeshAlgo.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKGeomAlgo/IntPolyh/IntPolyh_Intersection.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_ImpPrmIntersection.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKGeomAlgo/IntPatch/IntPatch_ImpImpIntersection.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKGeomAlgo/GTests/GeomFill_Gordon_Test.cxx | Range-based loop conversion in tests |
| src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_C1.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKFillet/BRepBlend/BRepBlend_Walking.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKFeat/BRepFeat/BRepFeat_RibSlot.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKFeat/BRepFeat/BRepFeat_MakePrism.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKFeat/BRepFeat/BRepFeat.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBool/TopOpeBRepBuild/TopOpeBRepBuild_Section.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBool/BRepFill/BRepFill_Sweep.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_6.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_5.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_3.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_11.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_CellsBuilder.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Builder_3.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Builder_2.cxx | Range-based loop conversion |
| src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_Builder.hxx | Range-based loop conversion |
| src/FoundationClasses/TKernel/Units/Units_Lexicon.cxx | Range-based loop conversion |
| src/FoundationClasses/TKernel/OSD/OSD_signal.cxx | Range-based loop conversion |
| src/FoundationClasses/TKernel/OSD/OSD_MemInfo.cxx | Range-based loop conversion |
| src/FoundationClasses/TKernel/NCollection/NCollection_Mat4.hxx | Range-based loop conversion |
| src/FoundationClasses/TKernel/NCollection/NCollection_Mat3.hxx | Range-based loop conversion |
| src/FoundationClasses/TKernel/Message/Message_CompositeAlerts.cxx | Range-based loop conversion |
| src/FoundationClasses/TKernel/GTests/NCollection_OrderedMap_Test.cxx | Range-based loop conversion in tests |
| src/FoundationClasses/TKernel/GTests/NCollection_OrderedDataMap_Test.cxx | Range-based loop conversion in tests |
| src/FoundationClasses/TKernel/GTests/NCollection_Map_Test.cxx | Range-based loop conversion in tests |
| src/FoundationClasses/TKernel/GTests/NCollection_KDTree_Test.cxx | Range-based loop conversion in tests |
| src/FoundationClasses/TKernel/GTests/NCollection_IndexedMap_Test.cxx | Range-based loop conversion in tests |
| src/FoundationClasses/TKernel/GTests/Handle_Advanced_Test.cxx | Range-based loop conversion in tests |
| src/FoundationClasses/TKMath/Poly/Poly_Triangulation.cxx | Range-based loop conversion |
| src/FoundationClasses/TKMath/Poly/Poly_MergeNodesTool.cxx | Range-based loop conversion |
| src/FoundationClasses/TKMath/MathSys/MathSys_Newton4D.hxx | Range-based loop conversion |
| src/FoundationClasses/TKMath/Bnd/Bnd_OBB.cxx | Range-based loop conversion |
| src/FoundationClasses/TKMath/Bnd/Bnd_Box.cxx | Range-based loop conversion |
| src/FoundationClasses/TKMath/BSplCLib/BSplCLib.cxx | Range-based loop conversion |
| src/DataExchange/TKXSBase/Interface/Interface_FloatWriter.cxx | Range-based loop conversion |
| src/DataExchange/TKXCAF/XCAFDoc/XCAFDoc_Editor.cxx | Range-based loop conversion |
| src/DataExchange/TKDEVRML/VrmlData/VrmlData_Scene.cxx | Range-based loop conversion |
| src/DataExchange/TKDESTL/RWStl/RWStl_Reader.cxx | Range-based loop conversion |
clang-tidy modernize-loop-convert replaced indexed loops with range-based for in several DumpJson() functions. OCCT_DUMP_FIELD_* macros stringify the expression to form JSON keys, so dumping myViewport[i] and then i changes the key name; in OpenGl_Context::DumpJson two adjacent loops additionally collided on the same key "i". Restore the indexed form in those loops to keep the original keys stable.
OpenGl_RaytraceGeometry::ReleaseTextures() iterates std::vector<GLuint64>, but clang-tidy modernize-loop-convert rewrote the loop with element type unsigned long. On Windows (LLP64) that is 32-bit, silently truncating bindless texture handles before passing them to glMakeTextureHandleNonResidentARB(). Use GLuint64 for the loop variable to preserve the full 64-bit width on every platform.
Member
|
My apologies, commit is very big to review. Many thanks for your commitment, after release the changes can be modified and merged ;) |
Contributor
Author
|
No worries at all — I understand reviewing such a large commit is a lot of work, so it makes total sense. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Applies
clang-tidy modernize-loop-convertacrosssrc/. Converts index-based for loops over arrays, STL-compatible containers, and begin/end-enabled NCollection types (List,DataMap,Map,Indexed{Data}Map,Array1,Sequence) to range-based for.OCCT's own
More()/Next()/Value()iterator idiom is not detected by this check and is left untouched — those loops stay as they are.Commits
01e45cd911— raw clang-tidy output (103 files)32ae48dc4b— clang-format pass across the changed files (73 files)Verification
-O3 -DNDEBUG).Excluded
src/Deprecated/OpenGl_glext.h,OpenGl_khrplatform.h)CLA ID
1142