C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 17 Jan 2026 10:25:53 -0800
On Saturday, 17 January 2026 08:37:45 Pacific Standard Time Sebastian Wittmeier
via Std-Proposals wrote:
> You say the clearing version of bit_cast could change the value on a
> round-trip cast, if there is a type with padding bits as intermediate type?

Yes, that would be a side-effect.

> Conceptually that should not work, as the type with padding has not enough
> bits for representation, but the one solution gives a compile error and the
> other just quietly clears bits and modifies the value.

Indeed.

One is potentially surprising behaviour, the other is an annoyance that might
need to be worked around. Neither is ideal.

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

Received on 2026-01-17 18:26:03