[cherry-pick stable/20230725] [Sema] -Wzero-as-null-pointer-constant: don't warn for __null (#69126) #8223
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.
The implementation of -Wzero-as-null-pointer-constant was done before the following fix has been committed to GCC:
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=752e7593b0f19af233a0b7e72daab8413662b605;hp=298434c916c14e8adca2cab8a746aee29038c5b3
As a result, clang and gcc diverge on the use of
__null
and, consequently, on the use ofNULL
on systems like Linux/macOS whereNULL
is defined as__null
.This is a problem for compatibility between gcc and clang, particularly for code bases that support C++98 or for single-source libraries that are implemented in C, but compiled as C++ via inclusion into a C++ translation unit. Code like this can not be changed to use
nullptr
, as it needs to maintain compatibility with C before C23 or C++ before C++11, but warns on the use ofNULL
in clang.The warning
Wzero-as-null-pointer-constant
is still useful with this change, as it allows to change0
toNULL
, which fixes gcc warnings and helps the reader distinguish between pointers and non-pointers. Users who require a full C++11 modernization pass can still use clang-tidy for that purpose.