Re: A VC8's bug??
The C++ standard you have quoted is OK, but when &A::a is converted to
a bool, it should be compared with the "NULL pointer" of pointer to
member but not the literal 0, which are totally different. So just have
a look at following code:
#include<iostream>
using namespace std;
class A
{
public:
int a;
int b;
};
int main(int argc,char **argv)
{
if (&A::a )
{
cout<<"OK\n";
}
cout<<&A::a<<endl;
return 0;
}
the output is 1 in VC7, so how can you explain it?
"John Carson =D0=B4=B5=C0=A3=BA
"
"Mihajlo Cvetanovic" <mac@RnEeMtOsVeEt.co.yu> wrote in message
news:eb02gUNMHHA.3552@TK2MSFTNGP03.phx.gbl
Igor Tandetnik wrote:
Since all-zeros is a valid pointer-to-member, a NULL
pointer-to-member is stored as 0xFFFFFFFF. When checking a variable,
as in "if (pInt)", the compiler correctly generates code that
compares the value with 0xFFFFFFFF. But in the statement "if
(&A::a)" the compiler checks against 0x0, and that's a bug.
Why would that be a bug? &A::a isn't something that is meant to be
checked, against zero or otherwise. It doesn't make much more sense to
check that than to check "if (&A)", IMHO.
By section 5.3.1/2 of the C++ standard:
<quote>
The result of the unary & operator is a pointer to its operand...If the
member is a nonstatic member of class C of type T, the type of the result=
is
"pointer to member of class C of type T."
[Example:
struct A { int i; };
struct B : A { };
... &B::i ... // has type int A::*
-end example]
</quote>
By Section 4.12/1:
<quote>
An rvalue of arithmetic, enumeration, pointer, or pointer to member type =
can
be converted to an rvalue of type bool. A zero value, null pointer value,=
or
null member pointer value is converted to false; any other value is
converted to true.
</quote>
--
John Carson