Skip to content

BUG: Return RieszRotationMatrix tolerance as RealType, not a temporary - #7247

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-riesz-dangling-getter
Nov 28, 2026
Merged

hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:bug-riesz-dangling-getter

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Fix a dangling reference in RieszRotationMatrix::GetMaxAbsoluteDifferenceCloseToZero(): it returned const ValueType & (std::complex<double>) for a double member, so the reference bound to a converted temporary. Clang warns -Wreturn-stack-address on every build of IsotropicWavelets.
Merge danger: two-way door; the getter's return type changes from std::complex<double> to double, matching the member and the setter. Nothing in ITK or the forest calls it, and its current result is undefined.

Shape of the change
 // itkRieszRotationMatrix.h
-  const ValueType &
+  const RealType &
   GetMaxAbsoluteDifferenceCloseToZero() const
   { return this->m_MaxAbsoluteDifferenceCloseToZero; }   // RealType member

itkRieszRotationMatrixTest now sets the tolerance on its default-constructed matrix and checks the getter returns it.

Evidence

Before (Homebrew clang, found while building #7246):

itkRieszRotationMatrix.h:199:12: warning: returning reference to local temporary object [-Wreturn-stack-address]
  199 |     return this->m_MaxAbsoluteDifferenceCloseToZero;

After: ninja IsotropicWaveletsTestDriver IsotropicWaveletsHeaderTest1 builds with 0 errors and no -Wreturn-stack-address warning; ctest -R RieszRotationMatrix 2/2 pass (itkRieszRotationMatrixTest2D, itkRieszRotationMatrixTest3D). pre-commit run --all-files passes.

Callers searched: git grep MaxAbsoluteDifferenceCloseToZero in ITK, and the forest build testbed's repos: none outside the header.

AI assistance
  • Tool: Claude Code (claude-opus-5-5)
  • Role: traced the warning, wrote the fix and the test check, and ran the local build and tests
  • Reviewed by the author

GetMaxAbsoluteDifferenceCloseToZero() returned const ValueType &
(std::complex<double>) for a RealType (double) member, so it bound the
reference to a converted temporary and returned it dangling. Clang
reports -Wreturn-stack-address:

  itkRieszRotationMatrix.h:199:12: warning: returning reference to local
  temporary object

Return const RealType &, the type the member and the setter use, and
check the round trip in itkRieszRotationMatrixTest.
@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module labels Nov 26, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review November 27, 2026 18:39
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · This PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This PR appears safe to merge.

Summary

Fixes GetMaxAbsoluteDifferenceCloseToZero() to return const RealType &, matching its stored tolerance.

  • The tolerance getter returns the matrix’s stored scalar type.

Reviews (1) · Last reviewed commit: "BUG: Return RieszRotationMatrix toleranc..." · Reviewed by Greptile

@hjmjohnson
hjmjohnson merged commit 8adc030 into InsightSoftwareConsortium:main Nov 28, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Filtering Issues affecting the Filtering module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants