This is the part of the example that I don't understand:
struct Y
{
int z;
};
int main()
{
alignas(Y) std::byte s[sizeof(Y)];
Y *q = new (&s) Y{2};
const int f = reinterpret_cast<Y *>(&s)->z; // Class member access is undefined behavior:
// reinterpret_cast<Y*>(&s) has value "pointer to s"
// and does not point to a Y object
}
And the whole example is at https://en.cppreference.com/w/cpp/utility/launder.
I don't understand why using reinterpret_cast<Y *>(&s)->z is undefined behavior. We have already constructed a Y object at the so-called "pointer to s", and also reinterpreted it to Y*, so why does it still say that "it does not point to a Y object" ?