Skip to content

[Common] Fix casts - #18382

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

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

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)

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

Copy link
Copy Markdown

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

@github-actions github-actions Bot changed the title Fix casts [Common] Fix casts Oct 21, 2026
@vkucera
vkucera marked this pull request as ready for review October 21, 2026 16:40
@alibuild

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for 01f656a at 2026-10-21 20:59:

## 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 17 errors and 525 warnings.'
Found 17 errors and 525 warnings.
++ [[ 17 -gt 0 ]]
++ cat /sw/BUILD/e37458bfcafcd2c91c66933242fa117b35163c02/O2Physics-code-check/errors.txt
Common/Core/macros/testMetadataHelper.C:66:103: error: Potential leak of memory pointed to by 'value' [clang-analyzer-unix.Malloc,-warnings-as-errors]
Common/Core/macros/testMetadataHelper.C:111:20: error: comparison of integers of different signs: 'size_type' (aka 'unsigned long') and 'int' [clang-diagnostic-sign-compare,-warnings-as-errors]
Common/TableProducer/PID/pidTOFBase.cxx:472:9: error: Value stored to 'weight' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
Common/TableProducer/PID/pidTOFMerge.cxx:438:11: error: Value stored to 'weight' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
Common/TableProducer/match-mft-ft0.cxx:370:9: error: Value stored to 'D' is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
Common/Tasks/qaMuon.cxx:541:109: error: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation,-warnings-as-errors]
Common/Tasks/qaMuon.cxx:550:98: error: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation,-warnings-as-errors]
Common/Tasks/qaMuon.cxx:567:109: error: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation,-warnings-as-errors]
Common/Tasks/qaMuon.cxx:573:98: error: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation,-warnings-as-errors]
Common/Tools/Multiplicity/macros/runCalibration.C:43:9: error: Value stored to 'hGlauberFitRange' during its initialization is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
Common/Tools/Multiplicity/macros/runCalibration.C:43:9: error: unused variable 'hGlauberFitRange' [clang-diagnostic-unused-variable,-warnings-as-errors]
Common/Tools/Multiplicity/macros/runGlauberFit.C:41:14: error: variable length arrays in C++ are a Clang extension [clang-diagnostic-vla-cxx-extension,-warnings-as-errors]
Common/Tools/Multiplicity/macros/runGlauberFit.C:41:21: error: variable length arrays in C++ are a Clang extension [clang-diagnostic-vla-cxx-extension,-warnings-as-errors]
Common/Tools/Multiplicity/macros/runGlauberFit.C:360:11: error: unused variable 'lPosText' [clang-diagnostic-unused-variable,-warnings-as-errors]
Common/Tools/Multiplicity/macros/runGlauberFit.C:361:11: error: unused variable 'lYShift' [clang-diagnostic-unused-variable,-warnings-as-errors]
Common/Tools/Multiplicity/macros/saveCorrelation.C:62:9: error: Value stored to 'hNpNc' during its initialization is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
Common/Tools/Multiplicity/macros/saveCorrelation.C:62:9: error: unused variable 'hNpNc' [clang-diagnostic-unused-variable,-warnings-as-errors]
++ [[ 525 -gt 0 ]]
++ cat /sw/BUILD/e37458bfcafcd2c91c66933242fa117b35163c02/O2Physics-code-check/warnings.txt
Common/Core/FFitWeights.cxx:66:3: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]
Common/Core/FFitWeights.cxx:66:13: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:68:3: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]
Common/Core/FFitWeights.cxx:68:14: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:78:14: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:84:15: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:98:12: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:133:21: warning: use nullptr [modernize-use-nullptr]
Common/Core/FFitWeights.cxx:143:13: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:148:14: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:154:47: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:155:25: warning: use nullptr [modernize-use-nullptr]
Common/Core/FFitWeights.cxx:158:46: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:168:12: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:182:41: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:196:12: warning: statement should be inside braces [readability-braces-around-statements]
Common/Core/FFitWeights.cxx:214:45: 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:15
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.

2 participants