STYLE: Replace declare-then-assign with initialization at declaration#6044
Open
hjmjohnson wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
Open
STYLE: Replace declare-then-assign with initialization at declaration#6044hjmjohnson wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
Conversation
f526ece to
0456324
Compare
Member
Author
|
Do: test this please |
|
Errors:
|
Member
Author
|
@greptileai review this draft before I make it official |
This comment was marked as resolved.
This comment was marked as resolved.
Modules/Core/Common/test/itkImageRegionConstIteratorWithOnlyIndexTest.cxx
Outdated
Show resolved
Hide resolved
4daba1b to
037539c
Compare
037539c to
f01c8e2
Compare
dzenanz
reviewed
Apr 13, 2026
6d789c9 to
8a9ba71
Compare
8a9ba71 to
be7d9e3
Compare
Mechanical conversion of two-line `T x; x = expr;` patterns to single-line `T x = expr;` (or `const T x = expr;` where possible) in Modules/Core/Common source and test files. No behavioral change. Tests exercise the same operations as before.
be7d9e3 to
4ca2f8f
Compare
Add verification of previously untested return values: - itkMatrixTest: assert GetInverse(), GetTranspose(), and operator* produce expected results (eliminates -Wunused-but-set-variable) - itkVectorGeometryTest: enable the commented-out VectorType brace initialization test and verify element values
Add section 6c covering the GCC -Wunused-but-set-variable warning that fires after declare-then-assign refactoring converts `T x; x = func();` to `const T x = func();` when the return value is never read. Also add a checklist item in the refactoring quick-reference section. Prefer adding test assertions in test code over suppressing with [[maybe_unused]] or static_cast<void>(). References: PR InsightSoftwareConsortium#6044, CDash build 11198750.
4ca2f8f to
35a1b23
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Merge variable declaration and subsequent assignment into single initialization-at-declaration across Modules/Core/Common (22 files). Adds
constwhere clang-tidymisc-const-correctnessidentifies immutable variables on changed lines.Changes by category
Forward-reference fixes (bugs in prior declare-then-init output):
itkPyImageFilter.hxx—result = PyObject_Call(..., args, ...)was moved aboveargs = PyTuple_Pack(...), creating use-before-declaration. Fixed by preserving correct ordering.itkImage.hxx—num = GetOffsetTable()[...]was moved aboveComputeOffsetTable(), reading stale data. Fixed by keeping compute before read.Dead code revival:
itkVectorGeometryTest.cxx— uncommented a test block with invalid C++ (VectorType vv = 0, 2, 4;) and rewrote with correct brace-initialization (VectorType vv{ { 0, 2, 4 } }).Mechanical changes (declare-then-assign → init at declaration):
Modules/Core/Common/{include,src,test}/Validation
misc-const-correctnessconst Type & const→const Type)