A word of warning, and a question for if anyone has encountered and/or has a solution for this issue (other than the obvious "don't allow this code").
If you (already) have an explicit conversion to a pointer type other than bool_type, the compiler may very well choose the non-bool_type, resulting in unexpected behavior.
example crashy:
class Testable
{
private:
Thing *mData;
public:
typedef void (xOGModelRefPtr::*bool_type)() const;
void type_does_not_support_comparisons() const {}
operator bool_type() const
{
return (mData && mData->IsValid()) ? Testable::type_does_not_support_comparisons : NULL;
}
Testable() : mData(NULL) {}
operator Thing*() const { return mData->mPtr; }
};
void fn(Thing *);
void main()
{
Testable t;
if(t) // crash on access of null mData->
fn(t);
}