I have some code and i can't understand is there a UB on dereferencing pointer or not. It works OK, but i have have doubts.
#include <iostream>
#include <cstdlib>
template <class T>
struct NullRef
{
static T& null(void)
{
static T* p(nullptr);
return *p;
}
static bool isNull(const T& t)
{
return &t == &null();
}
};
bool foo(const int& r = NullRef<int>::null()) {
return NullRef<int>::isNull(r);
}
int main()
{
std::cout << "isNull = "<<foo() << std::endl;
return 0;
}