Date: Wed, 21 Jan 2026 17:16:22 +0100
> There are exactly zero padding bits in an array of bytes (unsigned char),
> by
> definition.
>
So what?
That's exactly what I am proposing: that the std::bit_cast function,
> however
> it is implemented, write zero for padding bits of its input. That includes
> entire empty structs, if it is all padding.
>
That's also what I'm suggesting, albeit as a separate function.
> Ergo, if you want something that clears padding in-place, that requires a
> > std::clear_padding function, unless you treat std::bit_cast magically and
> > give it custom ABI.
>
> I don't see why.
>
Because the result of std::bit_cast has unspecified padding bits, so x =
std::bit_cast<X>(...) either makes the padding bits of x unspecified, or
alternatively, has no effect in the first place because assignment
operators do not modify padding.
> by
> definition.
>
So what?
That's exactly what I am proposing: that the std::bit_cast function,
> however
> it is implemented, write zero for padding bits of its input. That includes
> entire empty structs, if it is all padding.
>
That's also what I'm suggesting, albeit as a separate function.
> Ergo, if you want something that clears padding in-place, that requires a
> > std::clear_padding function, unless you treat std::bit_cast magically and
> > give it custom ABI.
>
> I don't see why.
>
Because the result of std::bit_cast has unspecified padding bits, so x =
std::bit_cast<X>(...) either makes the padding bits of x unspecified, or
alternatively, has no effect in the first place because assignment
operators do not modify padding.
Received on 2026-01-21 16:16:36
