COMP: Suppress -Wzero-as-null-pointer-constant in HDF5 ITK wrapper headers#5980
Open
blowekamp wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
Open
Conversation
Member
Author
|
@seanm Here is yet another approach to suppress some more of these warnings. |
Contributor
|
Yeah, this is a good solution too! |
7 tasks
…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.
7568399 to
6463793
Compare
Contributor
Greptile SummaryThis PR adds Key changes:
Confidence Score: 5/5
Important Files Changed
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
Reviews (1): Last reviewed commit: "COMP: Suppress -Wzero-as-null-pointer-co..." | Re-trigger Greptile |
dzenanz
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HDF5 C and C++ headers use
NULLas default function argument values, which triggers-Wzero-as-null-pointer-constantwarnings 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 asH5DataSet.h,H5Object.h,H5DcreatProp.h, andH5DataSpace.h.Example warning:
Changes
Add
#pragma clang diagnostic push/ignored/popguards 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 wrapperModules/ThirdParty/HDF5/src/itk_H5Cpp.h.in— C++ HDF5 header wrapperThe pattern mirrors
ITK_CLANG_PRAGMA_PUSH/ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constantfromitkMacro.h, implemented inline here because these headers must remain compatible with C translation units.A
__has_warningguard ensures the diagnostic is only suppressed on Clang versions that recognise the flag, and a sentinel#defineensures thepopis only emitted when apushwas actually performed.Testing
Built
ITKIOTransformHDF5andITKIOMINClocally with thedefaultpreset — zero warnings or errors with both targets.