P3969

Fixing std::bit_cast of types with padding bits

Latest is R3R2
Paperweight: Medium

> The following use of `std::bit_cast` has undefined behavior at compile time: > > ```cpp > constexpr auto x = std::bit_cast<__int128>(0.0L); // GCC accepts (x = 0), Clang rejects > ``` > > That is because an 80-bit x87 `long double` has 6 bytes of padding, and it is undefined behavior to map those padding bits onto non-padding bits in the destination type via `std::bit_cast`. [[bit.cast]](https://eel.is/c++draft/bit.cast) does not disqualify this use of `std::bit_cast` from being a constant expression.

Authors
Jan Schultke
Mailing
2026-07
Doc date
2026-06-28
Audience
LEWG
P

Revision history

  1. 2026-10
    R3 LEWG

    Fixing std::bit_cast of types with padding bits

  2. 2026-07
    R2 Selected (shown above)
  3. 2026-05
    R1 EWGLEWG

    Fixing std::bit_cast of types with padding bits

  4. 2026-02
    R0 LEWG

    Fixing std::bit_cast of types with padding bits