Consider
struct full
{
struct basic
{
int a = 1;
} base;
int b = 2;
};
void example()
{
alignas(full) std::byte storage[/* plenty of storage */];
full * pf = new (storage) full;
basic * pb = &pf->base;
new (storage) basic; // supposedly ends lifetime of *pf (right?)
// if doesn't, suppose we did pf->~full(); before this line
pb->a; // is this legal?
new (storage) full; // supposedly ends lifetime of *pb (right?)
// if doesn't, suppose we did pb->~basic(); before this line
pb->a; // is this still legal?
pf->b; // is this legal?
pf->base.a; // is this legal?
}
I would like to know if any of the above is legal or not, including understanding whether the destructor call is necessary before each step.