[patch] Let stddef.h redefine NULL if __need_NULL is set

Nico Weber thakis at chromium.org
Sun Apr 27 14:50:16 PDT 2014


Hi,

linux/stddef.h does something like

#undef NULL
#define NULL 0

when included for C++ translation units, and by transitivity it ends
up being pulled in often on linux (see llvm bug for examples).
-Wsentinel doesn't allow 0 as sentinel, leading to warnings such as

small.cc:6:18: error: missing sentinel in function call [-Werror,-Wsentinel]
  foo("bar", NULL);
                 ^
                 , NULL


To "fix" this, files defines __need_NULL and re-include stddef.h,
assuming that stddef.h redefines NULL if __need_NULL is defined
(similar to the __need_wint_t code that's already there). The attached
patch teaches clang's stddef.h about __need_NULL. (As far as I
understand, this shouldn't interfere with modules – linux/stddef.h
interferes with that, but it does so independently of this patch.)

Fixes PR12997. Patch mostly by Lei Zhang <thestig at chromium.org>, test
and tweaks by me.

Nico
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-neednull.patch
Type: application/octet-stream
Size: 1699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140427/606b8429/attachment.obj>


More information about the cfe-commits mailing list