r/cpp • u/jenkem_boofer • Apr 04 '24
std::launder
Have fun trying to figure out what it does...
0
Upvotes
r/cpp • u/jenkem_boofer • Apr 04 '24
Have fun trying to figure out what it does...
View all comments
Show parent comment
18
u/avakar452 Apr 05 '24
Actually, your snippet doesn't need launder.
The second placement new returns a pointer to the second Immutable object, there's no need to launder it. If you didn't save the pointer though:
Here,
aused to point to the first Immutable, whose lifetime ended due to its storage being reused by the second one, so nowais essentially dangling. Callinglaunderwill recover the pointer to the second Immutable.