[C++ Patch/RFC] PR 43906

Paolo Carlini paolo.carlini@oracle.com
Mon Aug 4 23:01:00 GMT 2014


Hi,

On 08/04/2014 10:45 PM, Jason Merrill wrote:
> On 08/04/2014 12:24 PM, Paolo Carlini wrote:
>> +           || (TYPE_PTR_P (type1) && VOID_TYPE_P (TREE_TYPE (type1))
>
> Why check for VOID_TYPE_P?  I'd think we would want to warn about 
> comparing to other null pointer values as well.
In fact I wondered about that a few minutes after sending my message... 
And this is what I figured out: normally we have hard errors from 
composite_pointer_type (eg, try scalar types, class types), even for 
null values. The only exception I have been able to find earlier today 
is that of pointer to the same function type, eg:

extern void z();
typedef void (*ptr)();
void i() { if ( z != (ptr)0 ); }

but in this case the C front-end too doesn't warn. In short, the case of 
(void*)0 seems very special.

However, something I did *not* notice earlier today, is that comparing a 
pointer to function to a generic void* leads to a pedwarn at the 
beginning of composite_pointer_type about the comparison itself. Thus 
it's debatable whether we also want the -Waddress warning... If you ask 
me, closing the bug with a testcase which checks that we warn for 
-pedantic about the comparison (if we don't have one already) would be 
Ok (vs EDG 4.9 too) What do you think?

Paolo.



More information about the Gcc-patches mailing list