Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++object lifetime and std::launderSingle-choice MCQ

Inside a single buffer you placement-new an `int` (lifetime starts), then without destroying it you placement-new a `float` into the exact same address. You then read the `int` through a pointer obtained before the second new. What is the precise problem?

alignas(int) unsigned char buf[sizeof(int)]; int* pi = new (buf) int{7}; float* pf = new (buf) float{1.5f}; int x = *pi; // ?