by codeflo · 4y ago · 0 comments
I did not write this comment about placement new specifically. It's just a thing that annoys me about the "learn a subset" idea. You still need to know at least enough about every feature to know whether it affects you. Placement new is perhaps not the best example there because it is relatively niche and self contained, true.
IIRC the issue was that vector construct one object at a time but then access it as if it was part of an array which was never constructed
In newer C++, thankfully, this is no longer required.
Edit: found a committee paper discussing exactly such cases:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p053...
Obj x;
x.use(); // ok
mutate(x); // does this call placement new?
x.use(); // may have undefined behavior
std::launder(&x)->use(); // may be necessary
x.use(); // may still have undefined behavior