Skip to content

Coding - Apply modernize-loop-convert for range-based for loops#1208

Open
jijinbei wants to merge 7 commits intoOpen-Cascade-SAS:IRfrom
jijinbei:modernize-loop-convert
Open

Coding - Apply modernize-loop-convert for range-based for loops#1208
jijinbei wants to merge 7 commits intoOpen-Cascade-SAS:IRfrom
jijinbei:modernize-loop-convert

Conversation

@jijinbei
Copy link
Copy Markdown
Contributor

@jijinbei jijinbei commented Apr 19, 2026

Summary

Applies clang-tidy modernize-loop-convert across src/. 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

  • Full Release build on Linux (GCC 15.2, C++17, -O3 -DNDEBUG).
  • All GTests pass: 6718 passed, 4 skipped.

Excluded

  • src/Deprecated/
  • Third-party Khronos headers (OpenGl_glext.h, OpenGl_khrplatform.h)

CLA ID

1142

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).
@jijinbei jijinbei marked this pull request as ready for review April 19, 2026 04:45
@dpasukhi dpasukhi requested a review from Copilot April 19, 2026 08:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/Visualization/TKOpenGl/OpenGl/OpenGl_Context.cxx Outdated
Comment thread src/Visualization/TKOpenGl/OpenGl/OpenGl_SceneGeometry.cxx Outdated
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.
@dpasukhi dpasukhi changed the base branch from master to IR April 19, 2026 16:02
@dpasukhi dpasukhi added the 3. CLA approved User has the signed CLA and ready to review or integration processes label Apr 28, 2026
@dpasukhi
Copy link
Copy Markdown
Member

My apologies, commit is very big to review.
Unfortunately, it will be not included in 8.0.0 (beta version tomorrow).

Many thanks for your commitment, after release the changes can be modified and merged ;)
I will apply more clang-tidy checks during coming hours.

@jijinbei
Copy link
Copy Markdown
Contributor Author

No worries at all — I understand reviewing such a large commit is a lot of work, so it makes total sense.
Totally fine on my side 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. CLA approved User has the signed CLA and ready to review or integration processes

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants