Skip to content

BUG: Drop explicit <double> template arg from std::abs in test#600

Merged
hjmjohnson merged 1 commit into
BRAINSia:mainfrom
hjmjohnson:fix-stdabs-template
May 22, 2026
Merged

BUG: Drop explicit <double> template arg from std::abs in test#600
hjmjohnson merged 1 commit into
BRAINSia:mainfrom
hjmjohnson:fix-stdabs-template

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Drop the explicit <double> template argument from std::abs in itkResampleInPlaceImageFilterTest.cxx, which became ambiguous on macOS SDK 26.5 / AppleClang 21 and broke the test build.

Root cause

macOS SDK 26.5's libc++ exposes the std::abs overload set via <__math/abs.h>, where the int / long / long long overloads plus the floating-point template are all visible. Writing std::abs<double>(...) forces template-argument deduction and leaves the integer candidates viable, so overload resolution is ambiguous:

error: call to 'abs' is ambiguous
   return std::abs<double>(input - desired) > tolerance * std::abs<double>(desired);
          ^~~~~~~~~~~~~~~~
note: candidate function [with $0 = double]  inline int       abs(int)
note: candidate function [with $0 = double]  inline long      abs(long)
note: candidate function [with $0 = double]  inline long long abs(long long)

The explicit template argument was never load-bearing: the inputs are double, so the non-template std::abs(double) from <cmath> is an exact match and resolves unambiguously. Dropping <double> fixes the build on current Apple toolchains with no behavior change on earlier SDKs or other platforms.

Surfaced while validating #598 (find_package(ANTS) migration) on AppleClang 21 / macOS SDK 26.5.

Local validation

Verified on the exact toolchain that surfaced the bug (Apple clang 21.0.0, arm64-apple-darwin25.5.0), compiling via ccache clang++ -std=c++17:

  • Pre-fix form std::abs<double>(...)error: call to 'abs' is ambiguous (candidates from MacOSX.sdk <__math/abs.h>).
  • This branch's form std::abs(...) → compiles cleanly (exit 0).

pre-commit run --all-files passes.

On macOS SDK 26.5's <__math/abs.h>, the std::abs overload set includes
both the templated floating-point form and integer-typed candidates,
making the explicit form `std::abs<double>(...)` ambiguous:

  error: call to 'abs' is ambiguous
     37 |   return std::abs<double>(input - desired)
        |          ^~~~~~~~~~~~~~~~

The explicit template argument was never load-bearing here --- inputs
are `double`, so the non-templated `std::abs(double)` overload from
<cmath> resolves unambiguously. Dropping `<double>` fixes the build
on current Apple toolchains without changing behavior on earlier
SDKs or other platforms.

Surfaced while validating BRAINSia#598 (find_package(ANTS)
migration) on AppleClang 21 / macOS SDK 26.5.
@hjmjohnson hjmjohnson marked this pull request as ready for review May 22, 2026 15:09
@hjmjohnson hjmjohnson merged commit 6595e24 into BRAINSia:main May 22, 2026
4 checks passed

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant