------- Comment #6 from l dot lunak at suse dot cz  2008-03-23 20:16 -------
> Hmm, 2*0.5 should be folded pretty early so Wconversion should see 1.0 which
> can be converted exactly to an integer (I think), so there should be no
> warning whatsoever. Are you sure you are using GCC 4.3? I cannot reproduce
> the warning.

I didn't realize gcc could optimize this example. It was just meant to be an
example of passing any float to foo(int). Make that foo(M_PI*10), foo(1.2),
foo(sin(bar)*100) or whatever. My point was that calling foo(int) as foo(var)
with var being a float is quite common code, whereas foo(NULL) is a mistake (or
brain-damage :) ). Therefore I'd like a way to get warned only about the latter
but not the sooner, which -Wconversion is not. That is why I changed this to an
enhancement after being told that -Wall not warning about foo(NULL) is not a
bug.

> > True. So, is there any example where use of NULL / __null in a non-pointer
> > context is a good idea?
> 
> Is there an example where it leads to bugs?

Yes. Consider you have code like this:

void foo(void* bar); // a function somewhere
...
foo( NULL ); // you call it
...

Now consider you want to add an overload foo(int). Now everybody who called the
original version as foo(0) is suddenly calling a different function, but I
intentionally used NULL to express I'm passing a null pointer, so I expect at
least a warning (and without all the stuff I'd get with -Wconversion). And this
example is actually based on a real problem that I had to debug in KDE
libraries.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35669

Reply via email to