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

Nico Weber thakis at chromium.org
Mon Apr 28 07:12:43 PDT 2014


On Mon, Apr 28, 2014 at 2:49 AM, Joerg Sonnenberger
<joerg at britannica.bec.de> wrote:
> On Sun, Apr 27, 2014 at 05:13:16PM -0700, Nico Weber wrote:
>> On Sun, Apr 27, 2014 at 4:07 PM, Joerg Sonnenberger
>> <joerg at britannica.bec.de> wrote:
>> > On Sun, Apr 27, 2014 at 02:50:16PM -0700, Nico Weber wrote:
>> >> small.cc:6:18: error: missing sentinel in function call [-Werror,-Wsentinel]
>> >>   foo("bar", NULL);
>> >
>> > This is just broken code. Why we do we want to workaround that?
>>
>> Linux is kind of common, and there's no good way to work around this
>> problem on an application code level that I can see.
>
> Yes, there is. It has always been the case that portable code *must* use
> (void *)NULL or equivalent as sentinal. For C++11, nullptr is
> acceptable, for C++03 NULL is not.

-Wsentinel is just one symptom: When using glibc headers, NULL will be
just 0 with clang, while it's __null in gcc (which means gcc will
provide better warnings and NULL checking). This patch fixes that.



More information about the cfe-commits mailing list