C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fixing std::bit_cast padding bit issues

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Fri, 23 Jan 2026 15:22:30 +0300
On 23 Jan 2026 14:54, Sebastian Wittmeier via Std-Proposals wrote:
> So you say clearing the padding would not necessarily have to survive
> passing function boundaries?

Yes, for passing or returning *by value*. Creating a copy of the object
does not necessarily copy padding bits. Passing by reference does not
create a copy, so it would preserve the padding contents.

> IMHO that construct is quite shaky (for human reasoning and teaching),
> if a type keeps the padding for the near future after clear_padding, but
> does not keep it intact for assignments, calling functions, returning
> from functions.

This utility is not intended for wide usage. Contexts where padding is
meaningful are fairly localized, but they do exist and are important. It
is fine to require to be careful around these places.

Received on 2026-01-23 12:22:34