Repository navigation
COMP: Scope the -Wallocator-wrappers suppression and document when to suppress - #7231
Merged
hjmjohnson merged 2 commits intoNov 27, 2026
Conversation
…Elements AppleClang flags functions named "alloc" that return a byte-typed pointer from an allocation. For unsigned char and signed char pixels, AllocateElements matches, but new TElement[n] is already typed, so the warning is a false positive. Returning std::unique_ptr<TElement[]> would avoid it, but AllocateElements is a protected virtual that subclasses override, so the definition alone is wrapped in a new ITK_CLANG_SUPPRESS_Wallocator_wrappers, guarded by __has_warning and listed in .clang-format StatementMacros. The same warning on vendored Eigen, VNL, and PocketFFT wrappers is left for upstream fixes.
Add compiler-cautions.md section 17: a suppression needs a confirmed false positive or code ITK cannot change, the narrowest scope, a one-line reason at the site, and a removal condition. The -Wallocator-wrappers case on AllocateElements is the worked example, including why a project-wide -Wno- flag was rejected.
hjmjohnson
marked this pull request as ready for review
November 23, 2026 21:11
Contributor
[Low impact] The PR appears safe to merge.
|
dzenanz
approved these changes
Nov 27, 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.
Clear AppleClang's
-Wallocator-wrappersfalse positive onImportImageContainer::AllocateElementswith a suppression scoped to that one definition, and document when ITK accepts a warning suppression. Complements #7228.Merge danger: two-way door; blast radius is AppleClang warning output only, with no API or behavior change.
Shape of the change
Why a suppression, and why only here
-Wallocator-wrappersis part of Apple's typed memory operations and is not in upstream LLVM. Probing with ITK's own compile line shows it fires on a function whose name contains "alloc" and that returns a byte-typed pointer (void *,char *,unsigned char *,signed char *) taken from an allocation.AllocateElementsmatches only forunsigned charandsigned charpixels;new TElement[n]is already typed, so this is a false positive.Code changes that avoid it were tested:
std::make_unique<T[]>(n).release()and catching onlystd::bad_allocstill warn. Returningstd::unique_ptr<TElement[]>does not warn, butAllocateElementsis a protectedvirtualthat subclasses override (for example BlueQuartz SIMPL'sitkImportDream3DImageContainer), so that is an API change, left for a later release. The suppression names it as the removal condition.The same warning on vendored Eigen, VNL (
vnl_sse_alloc), and PocketFFT wrappers is genuine type erasure and is left for upstream fixes. A project-wide-Wno-allocator-wrapperswas dropped from #7228 because it fixed nothing and would hide future cases in ITK code.Reference: Adopting type-aware memory allocation.
Evidence
AppleClang 21,
itkImageGTest.cxxcompiled with its build command plus-Wallocator-wrappers:ITKCommonGTestDriverandITKCommon1TestDriverbuild; 12 of 12 related tests pass (ImportImageContainer,Image.*,itkImageTest,itkImportImageTest,VectorImage).pre-commit run --all-filespasses.Not tested: the Mac26 AppleClang TSan nightly itself.
AI assistance