In short, the question is: if I call a no-op function on a null pointer is that UB?
Roughly speaking, I want to make a lightweight class which just becomes no-ops depending on build flags. For example:
class RealObject {
void foo() { /* do something real*/ }
};
class DummyObject {
inline void foo() {}
};
#ifdef DO_REAL
RealObject* obj = new Object();
#else
DummyObject* obj = nullptr;
#endif
obj->foo();
My gut tells me in the case where DummyObject gets used it violates something in the standard (don't what exactly what) but since foo() is no-op in practice it still could work as expected.
Can someone clarify the rules in this situation? thanks