Skip to content

[PWGLF] Fix casts - #18390

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

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

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

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for 4506f59 at 2026-10-21 21:34:

## 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 10 errors and 3790 warnings.'
Found 10 errors and 3790 warnings.
++ [[ 10 -gt 0 ]]
++ cat /sw/BUILD/a2698c28750c69a5c5b0f2d56f5d0f74c3bde1a8/O2Physics-code-check/errors.txt
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:226:10: error: std::move of the const variable 'name_' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:226:28: error: std::move of the const variable 'daughters_' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:226:51: error: std::move of the const variable 'daughterTrackSigns_' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:226:83: error: std::move of the const variable 'v0DaughterVec_' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:234:10: error: std::move of the const variable 'name_' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:234:28: error: std::move of the const variable 'daughters_' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:234:51: error: std::move of the const variable 'daughterTrackSigns_' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:257:30: error: Address of stack memory associated with temporary object of type 'TString' returned to caller [clang-analyzer-core.StackAddressEscape,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:258:33: error: Address of stack memory associated with temporary object of type 'TString' returned to caller [clang-analyzer-core.StackAddressEscape,-warnings-as-errors]
PWGLF/TableProducer/Nuspex/hypKfRecoTask.cxx:746:9: error: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation,-warnings-as-errors]
++ [[ 3790 -gt 0 ]]
++ cat /sw/BUILD/a2698c28750c69a5c5b0f2d56f5d0f74c3bde1a8/O2Physics-code-check/warnings.txt
PWGLF/DataModel/LFStrangenessTables.h:80:72: warning: redundant boolean literal in ternary expression result [readability-simplify-boolean-expr]
PWGLF/DataModel/LFStrangenessTables.h:694:52: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:695:52: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:696:48: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:697:48: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:698:52: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:699:52: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:1337:37: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:1341:37: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:1344:50: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:1345:54: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:1346:66: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:1347:66: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/DataModel/LFStrangenessTables.h:1350:36: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
PWGLF/TableProducer/Common/lfTPCPID.cxx:92:21: warning: member 'name' of type 'const std::string' (aka 'const basic_string<char>') is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
PWGLF/TableProducer/Common/lfTPCPID.cxx:115:15: warning: redundant string initialization [readability-redundant-string-init]
PWGLF/TableProducer/Common/lfTPCPID.cxx:116:15: warning: redundant string initialization [readability-redundant-string-init]
PWGLF/TableProducer/Common/lfTPCPID.cxx:332:13: warning: use starts_with instead of rfind [modernize-use-starts-ends-with]
PWGLF/TableProducer/Common/lfTPCPID.cxx:340:11: warning: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto]
PWGLF/TableProducer/Common/lfTPCPID.cxx:352:9: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
PWGLF/TableProducer/Common/lfTPCPID.cxx:366:13: warning: use starts_with instead of rfind [modernize-use-starts-ends-with]
PWGLF/TableProducer/Common/lfTPCPID.cxx:420:7: warning: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto]
PWGLF/TableProducer/Common/lfTPCPID.cxx:444:8: warning: constructor does not initialize these fields: ccdb [cppcoreguidelines-pro-type-member-init]
PWGLF/TableProducer/Common/lfTPCPID.cxx:802:10: warning: implicit conversion 'int64_t' (aka 'long') -> 'bool' [readability-implicit-bool-conversion]
[0 more errors; see full log]

Full log here.

abmodak
abmodak previously approved these changes Oct 21, 2026
@abmodak
abmodak enabled auto-merge (squash) October 21, 2026 19:52
romainschotter
romainschotter previously approved these changes Oct 21, 2026
@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 dismissed stale reviews from romainschotter and abmodak via f6ce857 October 22, 2026 15: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`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants