C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 23 Jan 2026 09:14:38 -0800
On Friday, 23 January 2026 09:05:20 Pacific Standard Time Arthur O'Dwyer via
Std-Proposals wrote:
> My impression is that you're concerned mainly with
> long double s = 3.14;
> std::array<int,4> d = std::bit_cast<std::array<int,4>>(s);
> which today is UB; I propose (in the P/R displayed above) to make it
> well-defined; my impression is that you propose to make it ill-formed,
> which is strictly less useful.


How about:
  using namespace std;
  auto d = bit_cast<array<int, 4>(bit_cast<uchar, 16>(s));

Would that be defined? And if so, what's the point of making the direct casting
undefined or ill-formed?

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

Received on 2026-01-23 17:14:51