On Dec 2, 2015, at 12:02 PM, Anders Montonen < email@hidden> wrote:
As I understand it, it has never been legal, since calling the method requires dereferencing a NULL pointer. From ISO/IEC 14882:2003(E)), paragraph 5.2.5/3: “If E1 has the type 'pointer to class X,' then the _expression_ E1->E2 is converted to the equivalent form (*(E1)).E2”
That doesn’t necessarily mean it dereferences the NULL pointer. If you take the address of the above _expression_, for example, there’s no such dereference. That’s basically what happens in a non virtual method call.
If x is a value of class/struct X, and y is a non-virtual method, then x.y() turns into X::y(&x).
So putting the two together, if x is a pointer to X, then x->y() turns into X::y(x). There’s no pointer dereference involved, and no issue if x is NULL. All that happens is that in the implementation of y(), `this` will be NULL.
The crux of that post is: “…the compiler can optimize the code comparing "this" pointer to null. According to the Standard, this cannot be null and therefore the checks and the corresponding code branches can be eliminated”.
Which goes back to my original question: did the C++ standard get updated to say that method calls to NULL are invalid?
—Jens |