DOC: Document two silent refactoring hazards — declare-then-init construction and const-addition overload changes
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- cpp
- Domain
- documentation
Research direction
Start in Documentation/ by locating the existing C++ style or modernization guidance, then review the cited itkPoint.h, itkPoint.hxx, itkVector.hxx, and itkCovariantVector.hxx references for context. Add two short entries covering declare-then-init construction and const-dependent overload resolution, including the minimal examples and the itk::Array correction; done means documentation only, with no code changes.
Written by the indexing model from the issue text.
Description
Two C++ refactoring hazards recur in ITK review and are not written down anywhere. Both cause silent behavior changes that compile cleanly, and both have already produced review findings.
Hazard 1 — T x = expr; is construction, not assignment
Converting
T x;
x = expr; // exercises operator=
to
T x = expr; // copy-initialization: exercises a CONSTRUCTOR
changes which special member function runs. For most types the observable
result is identical, but a test whose purpose is to exercise operator= is
silently no longer doing so.
Such tests must keep the two-line form, and should carry a short comment
saying why, so a later mechanical sweep does not re-merge them.
Hazard 2 — adding const can change overload resolution
When const and non-const overloads return different types, adding const
to a variable silently selects a different function with different semantics.
ITK has this exact shape today — verified on upstream/main:
// itkPoint.h:179,183 itkPoint.hxx:118-131
vnl_vector_ref<T> Point<T,N>::GetVnlVector(); // :120 — aliasing VIEW
vnl_vector<T> Point<T,N>::GetVnlVector() const; // :130 — deep COPY
The non-const overload returns a reference wrapper that aliases the point's
storage; the const overload returns an independent copy. Writing const auto v = p.GetVnlVector(); therefore yields a copy, and subsequent writes through
it no longer affect p.
The same const/non-const split exists in itkVector.hxx:142/149 and
itkCovariantVector.hxx:171/178.
Correction to an earlier note: this does not apply to itk::Array, which
derives from vnl_vector and has no GetVnlVector member.
Proposed work
Add both hazards to the C++ guidance under Documentation/ — most naturally
alongside the existing style/modernization material — each as a short entry
with the minimal example above. Two paragraphs; no code changes.
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 749
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 57
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from InsightSoftwareConsortium/ITK
-
type:Infrastructure
Difficulty 1/5 Under an hour Newbie friendliness 90/100
InsightSoftwareConsortium/ITK#6754 · 2 reactions ·
-
area:IO type:Testing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
InsightSoftwareConsortium/ITK#6750 ·
-
area:Documentation type:Documentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
InsightSoftwareConsortium/ITK#6744 · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
InsightSoftwareConsortium/ITK#6288 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
InsightSoftwareConsortium/ITK#6390 · 2 comments ·
All issues in InsightSoftwareConsortium/ITK
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
infiniflow/infinity#3502 ·