Something like template <typename Old, typename New, typename ...Args> New* replace(Old& old, Args&&... args) { static_assert(sizeof(New) <= sizeof(Old)); return new (&old) New(std::forward<Args>(args)...); }
patch forthcoming
Created attachment 370510 [details] patch
Comment on attachment 370510 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=370510&action=review > Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNode.h:56 > + return new (&old) New(std::forward<Args>(args)...); Don’t you have to save the address of “old” before you call its destructor?
(In reply to Myles C. Maxfield from comment #3) > Comment on attachment 370510 [details] > patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=370510&action=review > > > Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNode.h:56 > > + return new (&old) New(std::forward<Args>(args)...); > > Don’t you have to save the address of “old” before you call its destructor? Spoke with Myles offline. This code is probably fine (since dtor is just a method call), but we're just going to be explicit and do it before.
Created attachment 370512 [details] patch for landing
Comment on attachment 370512 [details] patch for landing Clearing flags on attachment: 370512 Committed r245706: <https://trac.webkit.org/changeset/245706>
All reviewed patches have been landed. Closing bug.
<rdar://problem/51079016>