[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).

Andy


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Reply to: