my question is how does new nullptr_t()
make sense ?
How does this make sense:
struct S
{
};
auto ptr = new S{};
This makes just about as much sense as dynamically allocating a nullptr_t
instance. S
has no contents, so it has no state outside of its address (two objects of the same type cannot have the same address, usually). So most functions that take an S
can take any S
instance and yield the same result. Oh yes, nullptr_t
has a few more bells and whistles on it, but it is mostly an object type that is distinct from all other object types.
Sure, generally speaking you wouldn't do this deliberately. But if you're in template code, and someone passes nullptr_t
as a template parameter, why would you want to make code that does new T{};
fail to compile? It doesn't hurt anything.