This is the mail archive of the 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, 29 Apr 2010, Shujing Zhao wrote:

> Hi,
> As Manuel's reply at,
> this patch is to change the warning of (z >= (void *)0) as same as the warning
> of (z >= 0), if z is a pointer.
> Tested on i686-pc-linux-gnu.
> Is it ok for trunk?

This patch is not correct.  Ordered comparisons of pointers to void are 
valid and so must not receive a pedwarn (must not receive an error with 

The existing code for these warnings about comparison with integer zero is 
certainly problematic - it makes no sense for

void *p;
f (void)
  (void) (p > 0);
  (void) (0 > p);

to get only one warning with -Wextra but two with -pedantic.  (Both 
alternatives should pedwarn if -pedantic, otherwise warn if -Wextra.)  If 
you also want to warn - not pedwarn, and so under -Wextra only - for 
ordered comparisons with a pointer-type null pointer constant, I think you 
should do so inside the case where comp_target_types has passed.

This sort of thing should best get four copies of any testcase (options 
"", "-pedantic", "-pedantic-errors", "-Wextra"), to verify properly what 
form of diagnostic is given in each case.

Joseph S. Myers

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