Summary: | Weird warnings about using (int)NULL | ||
---|---|---|---|
Product: | gcc | Reporter: | Ralph Loader <suckfish> |
Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | bonzini, gcc-bugs, gdr, manu, nathan |
Priority: | P3 | Keywords: | diagnostic |
Version: | 3.0.3 | ||
Target Milestone: | 4.3.0 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2006-03-01 02:15:18 | |
Attachments: | temp.cc |
Description
Ralph Loader
2002-01-07 22:46:00 UTC
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 |