[Bug c++/35669] NULL (__null) not considered different from 0 with C++
manu at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sun Mar 23 22:18:00 GMT 2008
------- Comment #7 from manu at gcc dot gnu dot org 2008-03-23 22:17 -------
(In reply to comment #6)
> 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.
>
manuel@gcc12:~$ cat test.c
#include <stdio.h>
void foo( void * a )
{
printf ("I'm foo(void*)\n");
}
void foo( int a )
{
printf ("I'm foo(int)\n");
}
int main()
{
foo (__null);
return 0;
}
manuel@gcc12:~$ /home/guerby/release/4.3.0/bin/g++ test.c -fpermissive -o test
test.c: In function 'int main()':
test.c:15: error: call of overloaded 'foo(NULL)' is ambiguous
test.c:3: note: candidates are: void foo(void*)
test.c:8: note: void foo(int)
Anyway, it is not me the one you have to convince, I cannot approve patches and
I said already I don't care which option controls the warning as long as it
makes some sense.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35669
More information about the Gcc-bugs
mailing list