Skip to content

COMP: Forward-declare itk::Indent in itkPrintHelper.h#6252

Merged
dzenanz merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-print-helper-indent-fwd-decl
May 12, 2026
Merged

COMP: Forward-declare itk::Indent in itkPrintHelper.h#6252
dzenanz merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-print-helper-indent-fwd-decl

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

Fix the common-mode compile error in itkPrintHelper.h that breaks 8+ Nightly / Expected Nightly platforms (Mac11/12/13/14/15/26.x, Windows VS2022 Debug, Ubuntu gcc11 TBB-Debug, Valgrind, Coverage) with the same shape CE=1 / TF=0 / TN=~2660 — one compile error in ITKCommon blocks the entire test grid.

Root cause

itkPrintHelper.h:97 uses an unqualified Indent in a parameter declaration:

namespace itk::print_helper
{
template <typename T>
inline void
PrintNumericTrait(std::ostream & os, const Indent & indent, ...)

itkPrintHelper.h is included from itkMacro.h, which is itself included from itkIndent.h. When itkIndent.h is the include-chain entry point (the common case for any header that streams an Indent), the recursive inclusion of itkIndent.h from itkPrintHelper.h's prologue is a header-guard no-op — class itk::Indent has not yet been declared when itkPrintHelper.h's body is parsed.

Stricter toolchain configurations reject this:

itkPrintHelper.h:97:44: error: unknown type name 'Indent'

Local builds against ITK's pixi-managed Clang tolerate it; the failures only surface on Apple Clang dbg / ASanUBSan / TSan / ClangMain, MSVC 2022 Static-Debug, gcc 11.4 TBB-Debug, valgrind, and coverage builds.

Fix

Mirror the existing NumericTraits forward declaration a few lines above, adding class Indent; inside the namespace itk { ... } block. Every PrintNumericTrait() call site already #includes itkIndent.h directly or transitively (they need the full definition to stream os << indent), so the forward declaration is sufficient for parameter-list parsing and the template instantiates against the full definition at every call site.

Affected builds on the 2026-05-11 dashboard
Build Status
Mac11.x-AppleClang-dbg CE=1 TN=2660
Mac12.x-AppleClang-dbg-arm64 CE=1 TN=2707
Mac13.x-AppleClang-dbg-Universal CE=1 TN=2660
Mac14.x-AppleClang-dbg-Universal CE=1 TN=2660
Mac15.x-AppleClang-dbg-ASanUBSan CE=1 TN=2660
Mac26.x-ClangMain-dbg-arm64 CE=1 TN=2666
Mac26.x-AppleClang-dbg-TSan CE=1 TN=2452
Windows11-VS2022-Static-DebugTBB CE=2 TN=2604
Ubuntu-22.04-gcc11.4-TBB-Debug CE=1 TN=2598
itk-valgrind CE=1 TF=2785
itk-coverage CE=1 TN=2866

@github-actions github-actions Bot added type:Compiler Compiler support or related warnings area:Core Issues affecting the Core module labels May 11, 2026
@hjmjohnson hjmjohnson marked this pull request as ready for review May 11, 2026 14:03
@hjmjohnson hjmjohnson self-assigned this May 11, 2026
@greptile-apps

This comment was marked as resolved.

Comment thread Modules/Core/Common/include/itkPrintHelper.h Outdated
itkPrintHelper.h is included from itkMacro.h. Common ITK headers include
itkIndent.h, which itself includes itkMacro.h, which transitively includes
itkPrintHelper.h. When itkIndent.h is the include-chain entry point, the
recursive inclusion of itkIndent.h from itkPrintHelper.h's prologue is a
header-guard no-op — class itk::Indent has NOT yet been declared at the
point itkPrintHelper.h is parsed.

Most toolchains tolerate this because the only reference to Indent in
this file is a function parameter declaration (`const Indent & indent`),
and many parsers accept forward use of an undeclared type at parse time.
Stricter configurations (Apple Clang dbg, AppleClang ASanUBSan, ClangMain,
TSan, gcc 11.4 TBB-Debug, MSVC 2022 Static-DebugTBB, Valgrind, Coverage)
reject it as:

    itkPrintHelper.h:97:44: error: unknown type name 'Indent'

The fix is the same pattern already used a few lines above for NumericTraits:
add an explicit forward declaration of class Indent inside namespace itk
before the namespace itk::print_helper block. Every PrintNumericTrait()
call site already #includes itkIndent.h directly or transitively (they
need to stream `os << indent`), so the forward declaration is sufficient
for the template's parameter list to parse; the full Indent definition is
visible at every instantiation site.

Symptom across 8+ Nightly / Expected Nightly platforms (2026-05-11):
CE=1 / TF=0 / TN=~2660 — one compile error in ITKCommon blocks the
entire test grid.
@hjmjohnson hjmjohnson force-pushed the fix-print-helper-indent-fwd-decl branch from 81627c6 to 514ff3c Compare May 11, 2026 14:12
@hjmjohnson
Copy link
Copy Markdown
Member Author

/azp run ITK.Linux

@hjmjohnson hjmjohnson requested a review from dzenanz May 11, 2026 18:33
@dzenanz dzenanz merged commit 0082640 into InsightSoftwareConsortium:main May 12, 2026
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Compiler Compiler support or related warnings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants