[all-commits] [llvm/llvm-project] cd29e1: [Sema] -Wzero-as-null-pointer-constant: don't warn...

Arseny Kapoulkine via All-commits all-commits at lists.llvm.org
Wed Oct 25 08:58:42 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: cd29e19e9476e221015d895618512717d872a83b
      https://github.com/llvm/llvm-project/commit/cd29e19e9476e221015d895618512717d872a83b
  Author: Arseny Kapoulkine <arseny.kapoulkine at gmail.com>
  Date:   2023-10-25 (Wed, 25 Oct 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/Sema.cpp
    M clang/test/SemaCXX/warn-zero-nullptr.cpp

  Log Message:
  -----------
  [Sema] -Wzero-as-null-pointer-constant: don't warn for __null (#69126)

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 of `NULL` on systems like Linux/macOS where
`NULL` 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 of `NULL` in clang.

The warning `Wzero-as-null-pointer-constant` is still useful with this
change, as it allows to change `0` to `NULL`, 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.




More information about the All-commits mailing list