Skip to content

[DPG] Fix casts - #18383

Open
vkucera wants to merge 1 commit into
AliceO2Group:masterfrom
vkucera:cast-DPG
Open

vkucera wants to merge 1 commit into
AliceO2Group:masterfrom
vkucera:cast-DPG

Conversation

@vkucera

@vkucera vkucera commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Fixes C-style, redundant, wrong, and dangerous casts (found by Clang-Tidy and cpplint).

  • Remove redundant casts. (readability-redundant-casting)
  • Remove const_cast. (cppcoreguidelines-pro-type-const-cast)
  • Replace C-style casts with static_cast. (google-readability-casting, cpplint: readability/casting)
  • Replace unsafe C-style casts with dynamic_cast. (cppcoreguidelines-pro-type-cstyle-cast)
  • Replace static_cast in downcasts with dynamic_cast. (cppcoreguidelines-pro-type-static-cast-downcast)
  • Replace reinterpret_cast with static_cast or dynamic_cast. (cppcoreguidelines-pro-type-reinterpret-cast)
  • Replace two-step casting through void* with reinterpret_cast. (bugprone-casting-through-void)

@github-actions github-actions Bot added the dpg label Oct 21, 2026
@github-actions

Copy link
Copy Markdown

O2 linter results: ❌ 0 errors, ⚠️ 411 warnings, 🔕 75 disabled

@github-actions github-actions Bot changed the title Fix casts [DPG] Fix casts Oct 21, 2026
@vkucera
vkucera marked this pull request as ready for review October 21, 2026 16:42
@alcaliva
alcaliva enabled auto-merge (squash) October 21, 2026 17:12
@alibuild

alibuild commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for 72760ec at 2026-10-22 01:04:

## sw/BUILD/O2Physics-code-check-latest/log
--
========== List of issues found ==========
++ echo 'To reproduce the results below locally, run: '\''aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=upstream/master'\''.'
To reproduce the results below locally, run: 'aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=upstream/master'.
++ echo 'To apply all automatic fixes, add the '\''-e O2PHYSICS_CHECKER_FIX=1'\'' option.'
To apply all automatic fixes, add the '-e O2PHYSICS_CHECKER_FIX=1' option.
++ echo 'See the documentation for more details at: <https://aliceo2group.github.io/analysis-framework/docs/tools/#running-with-o2physics-code-check>.'
See the documentation for more details at: <https://aliceo2group.github.io/analysis-framework/docs/tools/#running-with-o2physics-code-check>.
++ echo 'Found 4 errors and 538 warnings.'
Found 4 errors and 538 warnings.
++ [[ 4 -gt 0 ]]
++ cat /sw/BUILD/c597a34c23ff24199a4b80d4055bc904c62bd189/O2Physics-code-check/errors.txt
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:457:7: error: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation,-warnings-as-errors]
DPG/Tasks/AOTTrack/qaEfficiency.cxx:1044:26: error: logical expression is always true [misc-redundant-expression,-warnings-as-errors]
DPG/Tasks/AOTTrack/qaEfficiency.cxx:1806:9: error: Value stored to 'centrality' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
DPG/Tasks/AOTTrack/qaEfficiency.cxx:1807:9: error: Value stored to 'occupancy' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
++ [[ 538 -gt 0 ]]
++ cat /sw/BUILD/c597a34c23ff24199a4b80d4055bc904c62bd189/O2Physics-code-check/warnings.txt
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:56:8: warning: constructor does not initialize these fields: ccdb, nOrbits, minOrbit [cppcoreguidelines-pro-type-member-init]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:186:20: warning: narrowing conversion from 'double' to 'int' [bugprone-narrowing-conversions]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:414:19: warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:415:32: warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:418:21: warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:456:60: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:603:56: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:614:60: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:615:61: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:640:53: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:643:26: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:644:23: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:646:86: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:648:102: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:652:35: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:653:35: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:655:53: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:657:35: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:659:29: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:668:29: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:688:159: warning: redundant boolean literal in ternary expression result [readability-simplify-boolean-expr]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:691:44: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:691:78: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:720:30: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:725:51: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:729:42: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:741:30: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:746:41: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:763:46: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:767:47: warning: statement should be inside braces [readability-braces-around-statements]
[0 more errors; see full log]

Full log here.

@vkucera
vkucera marked this pull request as draft October 21, 2026 23:27
auto-merge was automatically disabled October 21, 2026 23:27

Pull request was converted to draft

@vkucera
vkucera force-pushed the cast-DPG branch 3 times, most recently from 2ff0579 to b3041b7 Compare October 26, 2026 14:33
Fixes C-style, redundant, wrong, and dangerous casts (found by Clang-Tidy and cpplint).

- Remove redundant casts. (`readability-redundant-casting`)
- Remove `const_cast`. (`cppcoreguidelines-pro-type-const-cast`)
- Replace C-style casts with `static_cast`. (`google-readability-casting`, cpplint: `readability/casting`)
- Replace unsafe C-style casts with `dynamic_cast`. (`cppcoreguidelines-pro-type-cstyle-cast`)
- Replace `static_cast` in downcasts with `dynamic_cast`. (`cppcoreguidelines-pro-type-static-cast-downcast`)
- Replace `reinterpret_cast` with `static_cast` or `dynamic_cast`. (`cppcoreguidelines-pro-type-reinterpret-cast`)
- Replace two-step casting through `void*` with `reinterpret_cast`. (`bugprone-casting-through-void`)
@vkucera
vkucera marked this pull request as ready for review November 2, 2026 19:38
@vkucera

vkucera commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Dear code owners, the PR is ready for review.

@alibuild

alibuild commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for 13bb30c at 2026-11-02 21:06:

## sw/BUILD/O2Physics-code-check-latest/log
--
========== List of issues found ==========
++ echo 'To reproduce the results below locally, run: '\''aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=upstream/master'\''.'
To reproduce the results below locally, run: 'aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=upstream/master'.
++ echo 'To apply all automatic fixes, add the '\''-e O2PHYSICS_CHECKER_FIX=1'\'' option.'
To apply all automatic fixes, add the '-e O2PHYSICS_CHECKER_FIX=1' option.
++ echo 'See the documentation for more details at: <https://aliceo2group.github.io/analysis-framework/docs/tools/#running-with-o2physics-code-check>.'
See the documentation for more details at: <https://aliceo2group.github.io/analysis-framework/docs/tools/#running-with-o2physics-code-check>.
++ echo 'Found 5 errors and 538 warnings.'
Found 5 errors and 538 warnings.
++ [[ 5 -gt 0 ]]
++ cat /sw/BUILD/69d6cfb1d42f676665c3a46418c7544708641be6/O2Physics-code-check/errors.txt
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:457:7: error: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation,-warnings-as-errors]
DPG/Tasks/AOTTrack/derivedDataCreatorD0Calibration.cxx:123:16: error: no header providing "o2::track::TrackParametrizationWithError" is directly included [misc-include-cleaner,-warnings-as-errors]
DPG/Tasks/AOTTrack/qaEfficiency.cxx:1044:26: error: logical expression is always true [misc-redundant-expression,-warnings-as-errors]
DPG/Tasks/AOTTrack/qaEfficiency.cxx:1806:9: error: Value stored to 'centrality' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
DPG/Tasks/AOTTrack/qaEfficiency.cxx:1807:9: error: Value stored to 'occupancy' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
++ [[ 538 -gt 0 ]]
++ cat /sw/BUILD/69d6cfb1d42f676665c3a46418c7544708641be6/O2Physics-code-check/warnings.txt
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:56:8: warning: constructor does not initialize these fields: ccdb, nOrbits, minOrbit [cppcoreguidelines-pro-type-member-init]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:186:20: warning: narrowing conversion from 'double' to 'int' [bugprone-narrowing-conversions]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:414:19: warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:415:32: warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:418:21: warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:456:60: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:603:56: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:614:60: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:615:61: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:640:53: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:643:26: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:644:23: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:646:86: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:648:102: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:652:35: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:653:35: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:655:53: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:657:35: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:659:29: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:668:29: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:688:159: warning: redundant boolean literal in ternary expression result [readability-simplify-boolean-expr]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:691:44: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:691:78: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:720:30: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:725:51: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:729:42: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:741:30: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:746:41: warning: statement should be inside braces [readability-braces-around-statements]
DPG/Tasks/AOTEvent/detectorOccupancyQa.cxx:763:46: warning: statement should be inside braces [readability-braces-around-statements]
[0 more errors; see full log]

Full log here.

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

Labels

Development

Successfully merging this pull request may close these issues.

3 participants