I know at least one case when this idiom is not only resolved, but also relied upon: Microsoft's MFC class CWnd provides a GetSafeHwnd member function that checks if this==NULL and returns without access to any member variables .
Of course, there are many people who claim that MFC is a very bad example.
Regardless of whether the behavior is undefined or not, in practice this is unlikely to behave badly. The compiler will treat a->foo() as A::foo(a) , which does not dereference the call site if foo not virtual.
Mark ransom
source share