I would like to replace code like this:
if ((obj != nullptr) && obj->is_valid()) with
if (obj->is_valid()) where
class Obj { bool is_valid() { if (this == nullptr) return false; // some more logic ... } ... }; Obviously there are 2 conditions:
objis always accessed via pointerObj::is_valid()is never virtual
This is based on the fact, that a non-virtual method accepts this as its 1-st argument, so that
obj->is_valid(); is rewritten as
Obj::is_valid(obj); While this code does work as expected with gcc-5.4.0, my question is whether this is a legitimate C++ code, that will be interpreted / optimized correctly by other (older / newer) C++ compilers?