Skip to content

COMP: Fix PrintNumericTrait build error in debug mode#6278

Closed
blowekamp wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
blowekamp:fix-PrintNumericTrait-include-order
Closed

COMP: Fix PrintNumericTrait build error in debug mode#6278
blowekamp wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
blowekamp:fix-PrintNumericTrait-include-order

Conversation

@blowekamp
Copy link
Copy Markdown
Member

Move itkPrintHelper.h include from itkMacro.h to the bottom of itkIndent.h, fixing a build error in debug mode.

Root cause

itkIndent.h includes itkMacro.h, which inside #ifndef NDEBUG re-included itkPrintHelper.h before class Indent was fully declared. PrintNumericTrait's os << indent then failed to resolve operator<<(ostream, const Indent &):

itkPrintHelper.h:101: error: no match for 'operator<<'
  (operand types are 'std::ostream' and 'const itk::Indent')

Moving the include to the bottom of itkIndent.h ensures itkPrintHelper.h always sees the complete class and its operator<<. The now-redundant class Indent; forward declaration in itkPrintHelper.h is also removed.

AI assistance

GitHub Copilot (Claude Sonnet 4.6) identified the circular include chain and proposed this fix. Verified locally by building ITKCommon with the debug CMake preset (GCC 13, -DCMAKE_BUILD_TYPE=Debug).

itkIndent.h includes itkMacro.h, which in debug builds (inside
#ifndef NDEBUG) re-included itkPrintHelper.h before class Indent
was fully declared.  PrintNumericTrait's `os << indent` then
failed to resolve operator<<(ostream, const Indent &).

Move the include to the bottom of itkIndent.h so itkPrintHelper.h
always sees the complete class and its operator<<.  Remove the now-
redundant forward declaration of class Indent from itkPrintHelper.h.
@github-actions github-actions Bot added type:Compiler Compiler support or related warnings area:Core Issues affecting the Core module labels May 14, 2026
};
} // end namespace itk

#ifndef NDEBUG
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need this debug guard? Don't we want print helpers to be available to release builds too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not able to follow the logic of what was originally done despite the length of the comments.

The "using namespace ::itk::print_helper;" was only in the itkDebugMacro, so it's not widely used in ITK. I am skeptical if the addition of the print_helper change was well thought out.

@blowekamp
Copy link
Copy Markdown
Member Author

Replaced by: #6280

@blowekamp blowekamp closed this May 14, 2026
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