This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, C] Warn ordered comparison pointer with null pointer constant
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Shujing Zhao <pearly dot zhao at oracle dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Manuel Lópe z-Ibáñez <lopezibanez at gmail dot com>, Paolo Carlini <paolo dot carlini at oracle dot com>
- Date: Thu, 6 May 2010 14:24:35 +0000 (UTC)
- Subject: Re: [PATCH, C] Warn ordered comparison pointer with null pointer constant
- References: <4BD94874.5070201@oracle.com> <Pine.LNX.4.64.1004291212510.3619@digraph.polyomino.org.uk> <4BDAACCB.1050301@oracle.com> <Pine.LNX.4.64.1004301051210.21231@digraph.polyomino.org.uk> <4BE1108B.5090200@oracle.com> <Pine.LNX.4.64.1005051547030.17841@digraph.polyomino.org.uk> <4BE290EB.80607@oracle.com>
On Thu, 6 May 2010, Shujing Zhao wrote:
> On 05/05/2010 11:49 PM, Joseph S. Myers wrote:
> > On Wed, 5 May 2010, Shujing Zhao wrote:
> >
> > > but would warn "comparison of distinct pointer types lacks a cast" for
> > >
> > > extern void p()
> > > if ( p > (void *)0)
> > >
> > > since the types are not equivalent. My question is should the warnings to
> > > be
> > > kept consistent to warn the "null pointer" for the latter test case?
> > > If it is yes, besides warning inside the "comp_target_types" conditional,
> > > a
> > > else if null_pointer_constant_p conditional would be needed before the
> > > "else"
> > > conditional.
> >
> > For the same reasons I have already explained it would be wrong to put any
> > null_pointer_constant_p conditional (generating warnings) before the "else"
> > cases that generate errors or pedwarns; those errors or pedwarns must always
> > be generated when the relevant conditions on the types are satisfied,
> > whether or not null pointer constants are involved. So if you give this
> > warning it must be in addition to any existing errors or pedwarns, not
> > replacing them. I do not believe it is worth giving it in the "else" cases
> > where there is a more serious problem getting an error or pedwarn; avoiding
> > unnecessary cascades of diagnostics seems like a good idea.
> >
> Ok. I got it. The attached four test cases indicate the warnings for ordered
> comparison of pointer with null pointer constant after applied the attached
> patch. Is it correct?
This patch version is OK.
--
Joseph S. Myers
joseph@codesourcery.com