The attached file, compiled with g++ -Wall generates: temp.cc: In function `void bar()': temp.cc:8: warning: passing NULL used for non-pointer argument passing 1 of `void foo(int)' temp.cc:8: warning: argument to non-pointer type `int' from NULL I think the warning message is bogus. The argument expression has been cast to an int, so the compiler should not warn about using it as an int argument. If it is decided that the warning message from line 8 is in fact correct, then line 9 should also give a warning (using NULL as a long is just as silly as using NULL as an int). Release: 3.0.3 Environment: Debian GNU Linux, i686. Debian gcc package gcc-3.0-3.0.3-1 How-To-Repeat: Compile attached file with g++ -Wall
State-Changed-From-To: open->analyzed State-Changed-Why: confirmed.
On the mainline (20030526), I only get one warning: pr5310.cc: In function `void bar()': pr5310.cc:9: warning: passing NULL used for non-pointer argument 1 of `void foo(int)' Here is the proprocessed form of the testcase: void foo (int); void foo (long); void bar() { foo ((int)__null); foo ((long)__null); }
(In reply to comment #2) > On the mainline (20030526), I only get one warning: > > pr5310.cc: In function `void bar()': > pr5310.cc:9: warning: passing NULL used for non-pointer argument 1 of `void > foo(int)' > > Here is the proprocessed form of the testcase: > void foo (int); > void foo (long); > > void bar() > { > foo ((int)__null); > foo ((long)__null); > } The issue here has several roots: (1) cp/call.c:convert_like_real() should warn only if !c_cast_p; (2) convert_like_real() was called (as convert_like_with_context) with c_cast_p set to false; which is one source of the bug (3) since __null is of type int, the cast to int was a no-op, and since the C++ front-end currently does not have a high level representation of the program (e.g. lowering is done as part of parsing), it does not have ways to make the difference. Patches to correct any point above will be a progress.
(convert_like_real gives me the creeps.) I must check whether this warning has been taken by the new Wconversion, which is not currently enabled by Wall.
(In reply to comment #3) > (3) since __null is of type int, the cast to int was a no-op, and > since the C++ front-end currently does not have a high level > representation of the program (e.g. lowering is done as part of > parsing), it does not have ways to make the difference. > Where is lowering performed? It actually seems that the cast (long)__null is performed somewhere (where?) while parsing, while (int)__null is just accepted as __null. I tried to follow up the code with just long i = (long) __null; but the C++ front-end is impossible to debug for me. It just jumps again and again to the same places. Is there any trick to debug this kind of thing?
(In reply to comment #4) > (convert_like_real gives me the creeps.) > > I must check whether this warning has been taken by the new Wconversion, which > is not currently enabled by Wall. > By the way, this is not enabled by Wall anymore. You need Wconversion for this.
*** Bug 33160 has been marked as a duplicate of this bug. ***
Subject: Bug number PR c++/5310 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00865.html
Subject: Bug 5310 Author: manu Date: Fri Nov 23 19:15:09 2007 New Revision: 130381 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130381 Log: 2007-11-23 Mark Mitchell <mark@codesourcery.com> Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR c++/5310 cp/ * call.c (convert_like_real): Build a zero constant when __null is converted to an integer type. testsuite/ * g++.dg/warn/pr5310.C: New. * g++.dg/warn/pr33160.C: New Added: trunk/gcc/testsuite/g++.dg/warn/pr33160.C trunk/gcc/testsuite/g++.dg/warn/pr5310.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c trunk/gcc/testsuite/ChangeLog
Fixed in GCC 4.3