C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 21 Jan 2026 10:32:09 -0800
On Wednesday, 21 January 2026 10:03:10 Pacific Standard Time Jan Schultke
wrote:
> Why are you saying that? How is the behaviour of std::bit_cast ABI in the
> first place?
>
> Because it's a function and returns by value, so it's limited by the calling
> conventions for the platform, and whether those preserve padding (they
> usually don't). Ergo, at least on a debug build, you're not getting any
> padding bits from a function call to std::bit_cast.

That's true, but only when you're casting back to the type with padding. If
the output is a byte array, there is no padding, therefore all bits are copied
intact.

The clear_padding_bits() function does need to modify an object, instead of
returning a new one though.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-01-21 18:32:17