https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90285
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Niall Douglas from comment #2) > To put this into a wider context, the detach and attach cast proposal passed > muster earlier this week at the WG14 meeting that I am currently sitting in. > The current C2x draft allows this implementation of "unidirectional > reinterpret casting with no aliasing of input with output" under its > "effective type" object model. > > (I will be taking this proposal to WG21 in July. Its paper number will be > P1631 "Object detachment and attachment") > > The ability to specify a non-aliasing reinterpret cast is valuable. If you > shrink the size of the Foo object e.g. https://godbolt.org/z/a1Fajj, GCC > generates ideal codegen. So I suspect the cause of this issue is probably > quite easy to fix. Not so, with small constant object size the memmoves are simply open-coded. "non-aliasing reinterpret cast"? Whatever that means. // Reinterpret bytes by copying (not UB for TC types) memmove(temp, &v, sizeof(T)); // Put reinterpreted bytes back. This avoids the UB // of reinterpret casting without creating new objects. memmove(ret, temp, sizeof(T)); not sure I understand this. Note that mem{cpy,move} transfer the effective type, this is a no-op. But well, C++ folks go wild these days... > Niall