Skip to content

Coding - Replace C-style casts with C++ cast operators#1206

Open
jijinbei wants to merge 3 commits intoOpen-Cascade-SAS:IRfrom
jijinbei:cstyle-cast-cleanup
Open

Coding - Replace C-style casts with C++ cast operators#1206
jijinbei wants to merge 3 commits intoOpen-Cascade-SAS:IRfrom
jijinbei:cstyle-cast-cleanup

Conversation

@jijinbei
Copy link
Copy Markdown
Contributor

@jijinbei jijinbei commented Apr 18, 2026

Summary

Mechanical replacement of C-style casts with named C++ cast operators
(static_cast / reinterpret_cast / const_cast) across src/.

Generated by clang-tidy 20.1.8 google-readability-casting via
run-clang-tidy -j 20 -fix, scoped to src/ and excluding the
Khronos headers and src/Deprecated/.

Scope

  • 751 files changed; 565 warnings fixed by clang-tidy.
  • Five sites needed manual correction where the tool's default
    static_cast choice did not compile (details in the commit body).

Excluded

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

Verification

Full Release build on Linux (C++17, GCC 15.2, Ninja, -O3 -DNDEBUG).
0 errors across all seven modules.

Relation to #1205

Independent of PR #1205 (the C++17 modernization sweep). Branched
from upstream master, no overlap in changed lines expected.

CLA ID

1142

Notes

  • Branch not named CR<issue_id> (no Mantis ticket yet).
  • Keeping as Draft until CLA is approved.

Applies clang-tidy 20.1.8 google-readability-casting across all
buildable modules (FoundationClasses, ModelingData, ModelingAlgorithms,
Visualization, DataExchange, ApplicationFramework, Draw).

751 files changed; clang-tidy replaced C-style casts with static_cast /
reinterpret_cast / const_cast or removed unnecessary ones. Four manual
corrections were needed where the tool's default choice did not
compile:

- OSD_SharedLibrary.cxx: dlsym() returns void*, converting to function
  pointer requires reinterpret_cast, not static_cast.
- TopLoc_Location.lxx: casts to `const void**` from const member
  address dropped a qualifier; rewrote as `const void* const*`.
- TopOpeBRep_sort.cxx: qsort callback casts from `const void*` needed
  `const BOA_t*` to preserve const.
- XCAFDoc_ShapeTool.cxx: casts to `void**` from const handle address
  dropped qualifiers; rewrote as `void* const*`.
- IntCurveSurface_InterUtils.pxx: tool emitted an extra closing
  parenthesis in two `(double)iU`-style casts; removed.

Excluded: src/Deprecated/, Khronos headers (OpenGl_glext.h,
OpenGl_khrplatform.h).

Verified by full Release build (Linux, GCC 15.2, Ninja, -O3 -DNDEBUG)
across all seven modules. 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dpasukhi dpasukhi added 2. Enhancement New feature or request 1. Coding Coding rules, trivial changes and misprints 3. CLA waited User need to process with CLA before review or integration processes labels Apr 18, 2026
jijinbei and others added 2 commits April 19, 2026 07:36
Addresses PR Open-Cascade-SAS#1206 feedback:

1. macOS Clang build: static_cast<Standard_ThreadId>(pthread_t) does
   not compile because pthread_t is a pointer (_opaque_pthread_t*) on
   macOS, unlike Linux where it is unsigned long. Added #elif
   defined(__APPLE__) branches in OSD_Thread.cxx using reinterpret_cast
   for the two sites (line 190 and 365).

2. Check code formatting: applied the CI's format.patch artifact. The
   clang-tidy google-readability-casting replacements left some lines
   outside the configured column width; clang-format restores the
   layout across 213 files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Applies the CI clang-format patch: nested preprocessor directives
inside a block need 2-space indentation per OCCT's .clang-format.
@jijinbei
Copy link
Copy Markdown
Contributor Author

Hand edits (clang-tidy google-readability-casting did the rest):

  • OSD_SharedLibrary.cxxdlsym() needs reinterpret_cast, not static_cast
  • TopLoc_Location.lxx, XCAFDoc_ShapeTool.cxx — rewrote to preserve const qualifier
  • TopOpeBRep_sort.cxx — qsort callback cast needed const preservation
  • IntCurveSurface_InterUtils.pxx — removed 2 extra closing parens emitted by clang-tidy
  • OSD_Thread.cxxpthread_t is a pointer on macOS, added #elif defined(__APPLE__) branches

@jijinbei jijinbei marked this pull request as ready for review April 19, 2026 00:13
@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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@jijinbei
Copy link
Copy Markdown
Contributor Author

CLA ID

1142

@dpasukhi dpasukhi added 3. CLA approved User has the signed CLA and ready to review or integration processes and removed 3. CLA waited User need to process with CLA before review or integration processes labels 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.

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

Labels

1. Coding Coding rules, trivial changes and misprints 2. Enhancement New feature or request 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