Compare with: std::shared_ptr which is empty but not null
The std::shared_ptr<T> aliasing constructor lets us play interesting games. The above SO post discusses when the first argument is std::shared_ptr<void>{nullptr}. I'm interested in the reverse. Is this guaranteed to keep the pointed-to object alive even though the shared_ptr "is" nullptr (and would be completely unreachable if it weren't that we keep a reference to it)?:
std::shared_ptr<S> ps = std::make_shared<S>();
auto& s = *ps; // Keep a reference to the S.
auto p = std::shared_ptr<S>(ps, nullptr); // Aliasing c'tor with null pointer.
ps = nullptr;
assert(ps == nullptr);
assert(p == nullptr);
foo(s); //< Is the S still alive here?