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

Shujing Zhao pearly.zhao@oracle.com
Thu May 6 09:51:00 GMT 2010


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?

Thanks
Pearly
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ChangeLog
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20100506/ce561ed5/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1651.patch
Type: text/x-patch
Size: 4970 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20100506/ce561ed5/attachment.bin>


More information about the Gcc-patches mailing list