https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102586

--- Comment #21 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 52413
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52413&action=edit
gcc12-pr102586.patch

Indeed, and when creating BIT_CAST_EXPR we actually verify those
trivially_copyable_p types.

This patch implements the rejection of pointers to non-trivially-copyable types
with the exception of &var or &parm, because in those cases we know it is
complete object type and so don't need to worry about it being just a
subobject.
I think the exception for that case is useful, so that users can still clear
the padding bits on them, but the restriction means that they need to use the
builtin directly or in a macro rather than through inline function.
But the risks of clobbering real data otherwise is real.

The other option would be just document that it shouldn't be called on
non-trivially-copyable base classes and make it user's responsibility.
For the <atomic> and std::bit_cast uses it doesn't really matter.

Reply via email to