[cfe-dev] [PATCH] -Wconversion-null

David Blaikie dblaikie at gmail.com
Wed Mar 14 21:38:11 PDT 2012


On Wed, Mar 14, 2012 at 9:15 PM, James K. Lowden
<jklowden at schemamania.org> wrote:
> On Tue, 13 Mar 2012 23:04:35 +0100
> Lubos Lunak <l.lunak at suse.cz> wrote:
>
>>  the attached patch adds option -Wconversion-null . It is pretty much
>> the same like http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35669 .
>
> Am I missing the point entirely?  If I do this:
>
> #undef NULL
> #define NULL 0

I believe/assume that would be non-conforming.

> The code you presented is valid C++ and the proposed warnings are all
> misplaced. If NULL is defined as

Actually if you do what you just did, the warnings won't trigger
because they're powered by the magic of how NULL is defined in the
glibc headers.

>        (void*)0;
>
> or somesuch, warnings should occur anyway on architectures that have
> bigger pointers than ints.

I believe that's entirely conforming - the size of the integer is not
important. All zero integer literals (including but not limited to
'\0' and false) are valid null pointer literals. We already have a
warning for 'false' as a null pointer literal, but we don't have a
warning for 0 as a null pointer literal (in part because it's /really/
common in existing code, so any such warning would probably be off by
default).

- David




More information about the cfe-dev mailing list