-
-
Notifications
You must be signed in to change notification settings - Fork 675
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
Add constexpr to compile time const variables #5086
Add constexpr to compile time const variables #5086
Conversation
a332ae8
to
507b2b3
Compare
@hjmjohnson Great work on these style improvements 😍 As I was working on the VectorImage bug, I was looking at the NumericTraits classes. You may want to look at these classes and see if methods like SetLength and others could be made constexpr. I think there are large potential for performance improvements using "if constexpr" statements in tight filter loops. I am sure your queue is filled with items, but just wanted to mention this for your consideration. |
Implements detection of local variables which could be declared as const but are not. Declaring variables as const is recommended by many coding guidelines, such as: ES.25 from the C++ Core Guidelines. cd ${BLDDIR} run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,misc-const-correctness -header-filter=.* -fix
IDE can identify these cases, but code changes are implemented manually REPLACE: (^ *)const *([a-zA-Z0-9_:]* [0-9a-zA-Z_]* = *[\+\-e0-9\.]+;) WITH: $1constexpr $2 REPLACE: (^ *)const (\w* \w*\{\}\;) WITH: $1constexpr $2
If statement with compile-time constant can be replaced with "if constexpr"
The test for epsilon > 0 is always true because epsilon is a constexpr greater than 0.
[CTest: warning matched] /Users/builder/externalModules/Filtering/ImageCompare/test/itkSimilarityIndexImageFilterTest.cxx:63:18: warning: result of comparison of 0 <= unsigned expression is always true [-Wtautological-unsigned-zero-compare] 63 | if (lower1 <= count && count <= upper1) | ~~~~~~ ^ ~~~~~ [CTest: warning suppressed] 1 warning generated.
Windows build failed when making an unused variable constexpr. Modules\Core\Common\test\itkVectorContainerTest.cxx(54): error C2127: 'p_null': illegal initialization of 'constexpr' entity with a non-constant expression Remove the unused variable to avoid the problem.
a1ab02c
to
bf64637
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
74916a5
into
InsightSoftwareConsortium:master
IDE can identify these cases, but code changes are implemented manually
If statement with compile-time constant can be replaced with "if constexpr"
PR Checklist