-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: replace C-style casts #3146
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-actions
bot
added
Component - Core
Affects the Core module
Component - Fatras
Affects the Fatras module
Component - Examples
Affects the Examples module
Event Data Model
Vertexing
Track Finding
labels
Apr 25, 2024
📊: Physics performance monitoring for e296442physmon summary
|
AJPfleger
commented
Apr 26, 2024
andiwand
previously approved these changes
Apr 26, 2024
Examples/Framework/include/ActsExamples/EventData/MuonSimHit.hpp
Outdated
Show resolved
Hide resolved
For the CI test, did you try |
github-actions
bot
added
Infrastructure
Changes to build tools, continous integration, ...
Seeding
labels
Apr 26, 2024
github-actions
bot
removed
the
Infrastructure
Changes to build tools, continous integration, ...
label
Apr 27, 2024
@CouthuresJeremy thanks, this one is a bit stricter, than planned, but looks good. |
andiwand
previously approved these changes
Apr 27, 2024
Examples/Io/NuclearInteractions/src/detail/NuclearInteractionParametrisation.cpp
Outdated
Show resolved
Hide resolved
andiwand
previously approved these changes
Apr 27, 2024
Examples/Io/NuclearInteractions/src/detail/NuclearInteractionParametrisation.cpp
Outdated
Show resolved
Hide resolved
Examples/Io/NuclearInteractions/src/detail/NuclearInteractionParametrisation.cpp
Outdated
Show resolved
Hide resolved
andiwand
approved these changes
Apr 27, 2024
kodiakhq bot
pushed a commit
that referenced
this pull request
Apr 28, 2024
Adds a new clang-tidy check. Necessary changes and more details in the PR below. blocked by: - #3146 ## Sample ``` ╭─ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Vertexing/SingleSeedVertexF─╮ │ 🟡 │ │ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Vertexing/SingleSeedVertexFi │ │ nderTests.cpp:47:10 WARNING [google-readability-casting] │ │ ╭──────────────────────────────────────────────────────────────────────────╮ │ │ │ C-style casts are discouraged; use static_cast │ │ │ │ 47 | return (int)(gen() / 4294967296. * (to - from) + from); │ │ │ │ | ^~~~~ │ │ │ │ | static_cast<int> │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ ──────────────────────────────────────────────────────────────────────────── │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Material/MaterialCompositio─╮ │ 🟡 │ │ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Material/MaterialComposition │ │ Tests.cpp:28:26 WARNING [google-readability-casting] │ │ ╭──────────────────────────────────────────────────────────────────────────╮ │ │ │ C-style casts are discouraged; use static_cast │ │ │ │ 28 | float carbonFraction = float(carbonWeight) / 255u; │ │ │ │ | ^~~~~ │ │ │ │ | static_cast<float> │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ ──────────────────────────────────────────────────────────────────────────── │ ╰──────────────────────────────────────────────────────────────────────────────╯ ```
EleniXoch
pushed a commit
to EleniXoch/acts
that referenced
this pull request
May 6, 2024
## Summary This pull request updates to use modern C++ style casts (`static_cast<int>(variable)`, `dynamic_cast`, `reinterpret_cast`, `const_cast`) instead of C-style casts like `(int)variable`. The change enhances code safety, readability, and maintainability by making type conversions explicit and type-safe. - Replaced most instances of C-style casts with their appropriate C++ style counterparts. - Reviewed each conversion to ensure the chosen C++ cast is suitable for its specific use case. - Use uniform initialization, where it is clear, e.g. `type{3.14}` ## Benefits - Improved Type Safety: Prevents the compiler from performing potentially unsafe conversions. - Increased Clarity and Maintainability: Makes the intentions clear, especially regarding the nature of each cast. - Easier to search for casts by search for `_cast<`. ## CI I experimented a bit with clang-tidy but couldn't find a proper test, that warns correctly. I tried `cppcoreguidelines-pro-type-cstyle-cast` but this is only suited for a subset. Using a regex like `\(([^\s()]+)\)[a-zA-Z_][a-zA-Z0-9_]*` creates too many false positives. `google-readability-casting` seems promising and will be added in: - acts-project#3149
EleniXoch
pushed a commit
to EleniXoch/acts
that referenced
this pull request
May 6, 2024
Adds a new clang-tidy check. Necessary changes and more details in the PR below. blocked by: - acts-project#3146 ## Sample ``` ╭─ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Vertexing/SingleSeedVertexF─╮ │ 🟡 │ │ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Vertexing/SingleSeedVertexFi │ │ nderTests.cpp:47:10 WARNING [google-readability-casting] │ │ ╭──────────────────────────────────────────────────────────────────────────╮ │ │ │ C-style casts are discouraged; use static_cast │ │ │ │ 47 | return (int)(gen() / 4294967296. * (to - from) + from); │ │ │ │ | ^~~~~ │ │ │ │ | static_cast<int> │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ ──────────────────────────────────────────────────────────────────────────── │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Material/MaterialCompositio─╮ │ 🟡 │ │ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Material/MaterialComposition │ │ Tests.cpp:28:26 WARNING [google-readability-casting] │ │ ╭──────────────────────────────────────────────────────────────────────────╮ │ │ │ C-style casts are discouraged; use static_cast │ │ │ │ 28 | float carbonFraction = float(carbonWeight) / 255u; │ │ │ │ | ^~~~~ │ │ │ │ | static_cast<float> │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ ──────────────────────────────────────────────────────────────────────────── │ ╰──────────────────────────────────────────────────────────────────────────────╯ ```
asalzburger
pushed a commit
to asalzburger/acts
that referenced
this pull request
May 21, 2024
## Summary This pull request updates to use modern C++ style casts (`static_cast<int>(variable)`, `dynamic_cast`, `reinterpret_cast`, `const_cast`) instead of C-style casts like `(int)variable`. The change enhances code safety, readability, and maintainability by making type conversions explicit and type-safe. - Replaced most instances of C-style casts with their appropriate C++ style counterparts. - Reviewed each conversion to ensure the chosen C++ cast is suitable for its specific use case. - Use uniform initialization, where it is clear, e.g. `type{3.14}` ## Benefits - Improved Type Safety: Prevents the compiler from performing potentially unsafe conversions. - Increased Clarity and Maintainability: Makes the intentions clear, especially regarding the nature of each cast. - Easier to search for casts by search for `_cast<`. ## CI I experimented a bit with clang-tidy but couldn't find a proper test, that warns correctly. I tried `cppcoreguidelines-pro-type-cstyle-cast` but this is only suited for a subset. Using a regex like `\(([^\s()]+)\)[a-zA-Z_][a-zA-Z0-9_]*` creates too many false positives. `google-readability-casting` seems promising and will be added in: - acts-project#3149
asalzburger
pushed a commit
to asalzburger/acts
that referenced
this pull request
May 21, 2024
Adds a new clang-tidy check. Necessary changes and more details in the PR below. blocked by: - acts-project#3146 ## Sample ``` ╭─ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Vertexing/SingleSeedVertexF─╮ │ 🟡 │ │ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Vertexing/SingleSeedVertexFi │ │ nderTests.cpp:47:10 WARNING [google-readability-casting] │ │ ╭──────────────────────────────────────────────────────────────────────────╮ │ │ │ C-style casts are discouraged; use static_cast │ │ │ │ 47 | return (int)(gen() / 4294967296. * (to - from) + from); │ │ │ │ | ^~~~~ │ │ │ │ | static_cast<int> │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ ──────────────────────────────────────────────────────────────────────────── │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Material/MaterialCompositio─╮ │ 🟡 │ │ /builds/acts/ci-bridge/src/Tests/UnitTests/Core/Material/MaterialComposition │ │ Tests.cpp:28:26 WARNING [google-readability-casting] │ │ ╭──────────────────────────────────────────────────────────────────────────╮ │ │ │ C-style casts are discouraged; use static_cast │ │ │ │ 28 | float carbonFraction = float(carbonWeight) / 255u; │ │ │ │ | ^~~~~ │ │ │ │ | static_cast<float> │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ ──────────────────────────────────────────────────────────────────────────── │ ╰──────────────────────────────────────────────────────────────────────────────╯ ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Component - Core
Affects the Core module
Component - Examples
Affects the Examples module
Component - Fatras
Affects the Fatras module
Component - Plugins
Affects one or more Plugins
Event Data Model
Seeding
Track Finding
Vertexing
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request updates to use modern C++ style casts (
static_cast<int>(variable)
,dynamic_cast
,reinterpret_cast
,const_cast
) instead of C-style casts like(int)variable
. The change enhances code safety, readability, and maintainability by making type conversions explicit and type-safe.type{3.14}
Benefits
_cast<
.CI
I experimented a bit with clang-tidy but couldn't find a proper test, that warns correctly. I tried
cppcoreguidelines-pro-type-cstyle-cast
but this is only suited for a subset. Using a regex like\(([^\s()]+)\)[a-zA-Z_][a-zA-Z0-9_]*
creates too many false positives.google-readability-casting
seems promising and will be added in: