Skip to content

COMP: Skip fpclassify for integral vnl_math classification predicates#9

Draft
hjmjohnson wants to merge 1 commit into
for/itk-vxl-masterfrom
comp-vnl-math-integral-fpclassify
Draft

COMP: Skip fpclassify for integral vnl_math classification predicates#9
hjmjohnson wants to merge 1 commit into
for/itk-vxl-masterfrom
comp-vnl-math-integral-fpclassify

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Skip fpclassify for integral vnl_math classification predicates so integer-typed vnl_matrix/vnl_vector compile on MSVC toolsets where fpclassify(<integral>) is ambiguous.

Root cause

numeric_predicates::isfinite/isnan/isinf/isnormal forward std::isfinite(arg) (etc.) for every TArg. For integral TArg this instantiates the Windows UCRT <corecrt_math.h> integer template

template <class _Ty> inline bool isfinite(_In_ _Ty _X) throw() { return fpclassify(_X) <= 0; }

where fpclassify(<integral>) is an ambiguous call (error C2668: float/double/long double) on e.g. MSVC 14.38.33130 (cl 19.38) + Windows SDK ≤ 10.0.22621. Every integer-typed vnl_matrix/vnl_vector TU fails to compile; newer toolsets (MSVC 14.44) are unaffected.

Fix: short-circuit integral arguments with if constexpr — an integer is always finite, never inf/NaN, normal when non-zero — avoiding the ambiguous SDK template.

Validation

The equivalent change applied to ITK's vendored copy of this file builds all of ITK (3396/3396 targets, 0 errors) on the failing toolchain (MSVC 14.38.33130, Windows SDK 10.0.22621.0). Carried as ITK PR InsightSoftwareConsortium/ITK#6451 pending this upstream fix.

AI assistance
  • Tool: Claude Code (claude-opus-4-8)
  • Role: diagnosed the ambiguous SDK fpclassify integer template, authored the if constexpr guard, validated via a full ITK build.

numeric_predicates::isfinite/isnan/isinf/isnormal forwarded
std::isfinite(arg) etc. for every TArg. For integral TArg this
instantiates the Windows UCRT <corecrt_math.h> integer template, where
fpclassify(<integral>) is an ambiguous call (error C2668) on some MSVC
toolsets, so vnl_matrix/vnl_vector of an integer type fail to compile.

Short-circuit integral arguments with if constexpr: an integer is always
finite, never inf/NaN, and normal when non-zero.
@hjmjohnson

Copy link
Copy Markdown
Member Author

Downstream consumer: InsightSoftwareConsortium/ITK#6451 carries this same change as an ITK-local patch to its vendored vnl_math.h, to unblock the ITK build until a VXL sync pulls in this fix. That ITK-local patch can be removed once this merges and is synced into ITK.

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.

2 participants