Do you mind elaborating? Modern compilers will definitely optimize out checks for null references [0] (but probably aren't guaranteed to), so checking after the fact seems like an iffy proposition to me at best.
[0]: https://cpp.godbolt.org/z/6ze9ns7cz
bool pointer(int* p) {
return p == nullptr;
}
bool reference(int& r) {
return &r == nullptr;
}
Become pointer(int*):
test rdi, rdi
sete al
ret
reference(int&):
xor eax, eax
ret
When compiled with Clang 23.1.0 and -O1.
I read the quote as "I have old code filled with bugs and UB. Using references don't magically solve the bugs"