This is one of those, hugh ? moments.
So, GCC behaves just like I would kinda expect it to but it looks VERY
strange.
It's one of those things that could cause silent strife if you included
files in the wrong order.
class X;
extern X a;
extern X b;
// class X is incomplete ... right ?
inline bool IsEqual( X & i, X & j )
{
// using operator & () on an incomplete class ... OK
// OK we know what this is supposed to do ... right ?
return (&i) == (&j);
}
class X
{
public:
// BUT WAIT
// Place a definition for operator & in the class.
// - basically throw allways.
X * operator & () { throw "Yikes"; };
};
inline bool IsEqualOverride ( X & i, X & j )
{
// using operator & () - should use the one defined in the cloass
//
return (&i) == (&j);
}
int main()
{
X x;
// should this throw ?
IsEqual( x, x ); // datapoint - GCC does not throw
// this should throw ... right ?
IsEqualOverride (( x, x ); // GCC throws here
}
Comment