P3969R0 — Fixing std::bit_cast of types with padding bits (9 items) LEWG
Jan Schultke
This paper addresses the undefined behavior that arises when using std::bit_cast to convert types with padding bits (e.g., x87 long double) to types without padding bits (e.g., __int128), where the current specification makes such specializations equivalent to std::unreachable regardless of the argument. Two solutions are presented: a two-function solution that makes the degenerate form of std::bit_cast ill-formed and adds a new std::bit_cast_zero_padding function that treats source padding bits as zero, or a single-function solution that changes std::bit_cast itself to treat padding bits as zero, applied as a DR against C++20.