Skip to content

COMP: Suppress -Wzero-as-null-pointer-constant in HDF5 ITK wrapper headers#5980

Open
blowekamp wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
blowekamp:fix-hdf5-wzero-as-null-pointer-constant
Open

COMP: Suppress -Wzero-as-null-pointer-constant in HDF5 ITK wrapper headers#5980
blowekamp wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
blowekamp:fix-hdf5-wzero-as-null-pointer-constant

Conversation

@blowekamp
Copy link
Member

Summary

HDF5 C and C++ headers use NULL as default function argument values, which triggers -Wzero-as-null-pointer-constant warnings on Clang when building with -Weverything. These warnings appear in the ITK nightly dashboard (e.g. Mac13.x-AppleClang-dbg-Universal) for HDF5 C++ headers such as H5DataSet.h, H5Object.h, H5DcreatProp.h, and H5DataSpace.h.

Example warning:

Modules/ThirdParty/HDF5/src/itkhdf5/c++/src/H5DataSet.h:98:38: warning:
  zero as null pointer constant [-Wzero-as-null-pointer-constant]
      void *op_data = NULL);

Modules/ThirdParty/HDF5/src/itkhdf5/c++/src/H5Object.h:83:85: warning:
  zero as null pointer constant [-Wzero-as-null-pointer-constant]

Changes

Add #pragma clang diagnostic push/ignored/pop guards in the two ITK HDF5 wrapper headers to suppress the warning around the HDF5 includes:

  • Modules/ThirdParty/HDF5/src/itk_hdf5.h.in — C HDF5 header wrapper
  • Modules/ThirdParty/HDF5/src/itk_H5Cpp.h.in — C++ HDF5 header wrapper

The pattern mirrors ITK_CLANG_PRAGMA_PUSH / ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant from itkMacro.h, implemented inline here because these headers must remain compatible with C translation units.

A __has_warning guard ensures the diagnostic is only suppressed on Clang versions that recognise the flag, and a sentinel #define ensures the pop is only emitted when a push was actually performed.

Testing

Built ITKIOTransformHDF5 and ITKIOMINC locally with the default preset — zero warnings or errors with both targets.

@github-actions github-actions bot added type:Compiler Compiler support or related warnings area:ThirdParty Issues affecting the ThirdParty module labels Mar 24, 2026
@blowekamp
Copy link
Member Author

@seanm Here is yet another approach to suppress some more of these warnings.

@seanm
Copy link
Contributor

seanm commented Mar 24, 2026

Yeah, this is a good solution too!

…aders

HDF5 C and C++ headers use NULL as default function arguments, triggering
-Wzero-as-null-pointer-constant on Clang with -Weverything. For example:

  Modules/ThirdParty/HDF5/src/itkhdf5/c++/src/H5DataSet.h:98:38: warning:
    zero as null pointer constant [-Wzero-as-null-pointer-constant]
        void *op_data = NULL);

  Modules/ThirdParty/HDF5/src/itkhdf5/c++/src/H5Object.h:83:85: warning:
    zero as null pointer constant [-Wzero-as-null-pointer-constant]

Add clang diagnostic push/pop guards in itk_hdf5.h.in and itk_H5Cpp.h.in
to suppress the warning around the HDF5 includes. The pattern follows the
ITK_CLANG_PRAGMA_PUSH / ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
convention from itkMacro.h, implemented inline for C compatibility.
@blowekamp blowekamp force-pushed the fix-hdf5-wzero-as-null-pointer-constant branch from 7568399 to 6463793 Compare March 25, 2026 10:12
@blowekamp blowekamp marked this pull request as ready for review March 25, 2026 12:41
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 25, 2026

Greptile Summary

This PR adds #pragma clang diagnostic push/ignored/pop guards around third-party HDF5 include directives in two ITK wrapper header templates (itk_H5Cpp.h.in and itk_hdf5.h.in) to suppress -Wzero-as-null-pointer-constant warnings emitted by HDF5 C++ headers when building with -Weverything. The approach is minimal, targeted, and consistent with the existing ITK_CLANG_PRAGMA_PUSH / ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant pattern in itkMacro.h.

Key changes:

  • Both wrapper headers now use #if defined(__clang__) && defined(__has_warning)__has_warning("-Wzero-as-null-pointer-constant") to conditionally emit the diagnostic push and ignored pragmas.
  • A sentinel #define (ITK_H5CPP_SUPPRESS_… / ITK_HDF5_SUPPRESS_…) tracks whether a push occurred, ensuring the pop is only emitted when paired.
  • The sentinel macro is #undef'd after the pop, leaving no macro pollution in consuming translation units.
  • The pattern is implemented inline rather than via itkMacro.h macros because itk_hdf5.h.in must remain compatible with C translation units.

Confidence Score: 5/5

  • This PR is safe to merge — the changes are narrowly scoped, use preprocessor guards that are harmless on non-Clang toolchains, and follow an established ITK pattern.
  • Both changed files are .h.in templates only processed by CMake and then included as headers. The pragma guards are Clang-only (correctly gated with defined(__clang__)), use __has_warning to avoid unknown-flag warnings on older Clang versions, and correctly pair every push with a pop via a sentinel macro. No logic, build system, or API changes are involved.
  • No files require special attention.

Important Files Changed

Filename Overview
Modules/ThirdParty/HDF5/src/itk_H5Cpp.h.in Adds clang diagnostic push/pop guards around the HDF5 C++ header include to suppress -Wzero-as-null-pointer-constant; implementation is clean and uses the established ITK sentinel-macro pattern.
Modules/ThirdParty/HDF5/src/itk_hdf5.h.in Adds identical clang diagnostic guards around the HDF5 C header include; inline implementation (not via itkMacro.h) is correct because this header must remain C-compatible.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["TU includes itk_H5Cpp.h or itk_hdf5.h"] --> B{"defined __clang__ AND defined __has_warning"}
    B -- No --> E["Include HDF5 header without pragma changes"]
    B -- Yes --> C{"__has_warning -Wzero-as-null-pointer-constant"}
    C -- No --> E
    C -- Yes --> D["pragma clang diagnostic push and ignored\ndefine sentinel macro"]
    D --> F{"ITK_USE_SYSTEM_HDF5 defined?"}
    E --> F
    F -- Yes --> G["Include system H5Cpp.h or hdf5.h"]
    F -- No --> H["Include bundled itkhdf5 header"]
    G --> I{"sentinel macro defined?"}
    H --> I
    I -- Yes --> J["pragma clang diagnostic pop\nundef sentinel macro"]
    I -- No --> K["End of header"]
    J --> K
Loading

Reviews (1): Last reviewed commit: "COMP: Suppress -Wzero-as-null-pointer-co..." | Re-trigger Greptile

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants