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, 29 Apr 2010, Shujing Zhao wrote:

> Hi,
> As Manuel's reply at http://gcc.gnu.org/ml/gcc-patches/2010-04/msg01425.html,
> 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 
-pedantic-errors).

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

void *p;
void
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
joseph@codesourcery.com


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