This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, C] Warn ordered comparison pointer with null pointer constant


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]