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

James K. Lowden jklowden at schemamania.org
Thu Mar 15 03:25:12 PDT 2012


On Thu, 15 Mar 2012 09:21:31 +0100
Lubos Lunak <l.lunak at suse.cz> wrote:

> > #undef NULL
> > #define NULL 0
> >
> > The code you presented is valid C++ and the proposed warnings are
> > all misplaced.
> 
>  It is valid C++, but that is why it is a warning and not an error.
> All warnings are about code which is technically valid, yet is (more
> or less) likely a mistake.

No, I can't agree.  The purpose of a warning is to indicate when a
particular operation or construction might be unsafe.  A warning about
something that cannot possibly be an error (as far as the machine is
concerned) is just noise.  

You are diving here into the semantics of the name "NULL", and it's
hopeless.  If I say

	#define NOPTR NULL
or
	typedef NULL NOPTR;

And then use NOPTR instead, have I not circumvented your warning and
produced identical machine code?  Is the resulting source code any
"(more or less) likely a mistake"?

As the standard doesn't define NULL, the user is free to define it at
will.  Since the compiler can't know what "NULL" means to the human,
it can't offer any advice about it.  

--jkl



More information about the cfe-dev mailing list