Pointer laundering is about object lifetime and provenance. Whenever you're asking for a pointer to an object, that object better be alive. In that case, there are some properties associated with that pointer, like is it valid, or does it point to a sub-object like f.e. an array element, or more. As soon as you acquire a pointer to something const, the compiler can take advantage of that promise and create code that strongly believes in the pointed-to object not being mutated during the lifetime of the pointer. Laundering a pointer strips the compiler off of its deeply ingrained believes about the object it is pointing to, preparing it to something new to believe in.
2
u/vickoza Apr 05 '24 edited Apr 06 '24
From my point of view
std::launderis a way to reduce undefined behavior by making sure the type is the correct typed,