[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: comparing function pointer with int does not produce error



> > I'll take another attempt at declaring gcc behaviour to be correct.
> > According to 4.10/1, "success" is a null pointer constant:
> > 
> > # A null pointer constant is an integral constant expression (5.19)
> > # rvalue of integer type that evaluates to zero. A null pointer
> > # constant can be converted to a pointer type; the result is the null
> > # pointer value of that type and is distinguishable from every other
> > # value of pointer to object or pointer to function type.
> > 
> > 5.19/1 defines "integral constant expressions":
> > 
> > # An integral constant-expression can involve only literals (2.13),
> > # enumerators, const variables or static data members of integral or
> > # enumeration types initialized with constant expressions (8.5),
> > # non-type template parameters of integral or enumeration types, and
> > # sizeof expressions.
> 
> Then why does the following NOT compile:
> 
> void stat ();
> enum {success};
> void monk ()
> {
>   if (stat == success);
> }
> 
> cbool.cpp:6: no match for `void (&)() == <anonymous enum>' operator
> 
> As success is an enumerator which is a integral constant-expression by your
> definition above; it also has zero value and thus must be a "null pointer
> constant" and hence the comparisom should be allowed (however distasteful
> that may be).

In this code, "success" does not have integer type. 3.9.1/7 specifies

# Types bool, char, wchar_t, and the signed and unsigned integer types
# are collectively called integral types. A synonym for integral type
# is integer type.

Since a null pointer constant must be of integer type, "success" does
not qualify. Change it to "(int)success", and it compiles.

Regards,
Martin



Reply to: