Skip to content

BUG: Remove redundant m_Threader shadow in MatchCardinalityImageToImageMetric#6257

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:shadow-fix-matchcardinality
May 12, 2026
Merged

BUG: Remove redundant m_Threader shadow in MatchCardinalityImageToImageMetric#6257
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:shadow-fix-matchcardinality

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

Remove MatchCardinalityImageToImageMetric's redundant m_Threader shadow. The base ImageToImageMetric constructor already initializes its protected m_Threader to MultiThreaderBase::New() — identical to the subclass's intended default — so the subclass redeclaration served no purpose.

The shadow and why it was 100% redundant

itkMatchCardinalityImageToImageMetric.h:189 declared (in private:):

MultiThreaderBase::Pointer m_Threader{ MultiThreaderBase::New() };

itkImageToImageMetric.h:632 declares (in protected:):

MultiThreaderBase::Pointer m_Threader{};

The base's in-class init produces a null pointer, but the base's constructor (itkImageToImageMetric.hxx) initializes the field in its member-initializer list:

: ...
, m_Threader(MultiThreaderBase::New())

So when a MatchCardinalityImageToImageMetric is constructed, the base constructor runs first and sets m_Threader to a fresh MultiThreaderBase::New(). Then the subclass's in-class init for its shadow runs and ALSO produces a fresh New(). Two threaders allocated; only the subclass's shadow is reachable via the subclass's GetMultiThreader(). The base's threader is orphaned.

The fix
  1. Delete the m_Threader redeclaration in MatchCardinalityImageToImageMetric's private: section.
  2. Qualify the GetMultiThreader() accessor with this-> so the lookup resolves to the inherited protected member: return this->m_Threader;.

No constructor change is needed because the base already initializes the field.

Net diff: 4 lines removed, 1 line modified.

Local verification
  • pre-commit run --all-files passes.
  • ninja ITKRegistrationCommonHeaderTest1 ITKRegistrationCommonHeaderTest2 builds clean.
  • itkMatchCardinalityImageToImageMetricTest CTest: pre-existing baseline failure on this machine (missing Spots.png ExternalData fixture) — verified to fail identically on upstream/main HEAD without my change. Not a regression from this PR.

No new GTest was added because the shadow removal is byte-equivalent (base ctor produces the same New() pointer the subclass's shadow used to allocate). The single existing public accessor (GetMultiThreader) is exercised by the existing test driver.

…geMetric

MatchCardinalityImageToImageMetric redeclared m_Threader that
shadows ImageToImageMetric's protected m_Threader. The base's
constructor already initializes m_Threader to MultiThreaderBase::New()
identical to the subclass's intended default, so the shadow was
purely redundant. Update GetMultiThreader to qualify with this->
and rely on the inherited member.
@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances area:Registration Issues affecting the Registration module labels May 12, 2026
@hjmjohnson
Copy link
Copy Markdown
Member Author

@greptile review

@greptile-apps

This comment was marked as resolved.

@hjmjohnson hjmjohnson marked this pull request as ready for review May 12, 2026 14:51
@hjmjohnson hjmjohnson merged commit 64c794e into InsightSoftwareConsortium:main May 12, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Registration Issues affecting the Registration module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants