C++ Logo

std-proposals

Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Fri, 23 Jan 2026 19:02:24 +0100
I am trying to summarize: So you define that std::clear_padding(T& t) would act on the lvalue t. t (as a lvalue) has a defined address in memory. All the padding bits/bytes are zeroed. Any access to the underlying storage (e.g. as std::byte or unsigned char) would read the zeroes. Any direct read or write of type T would still have or create indeterminate padding bits and bytes. Using t as a reference parameter would keep the cleared padding bits, using it as a value parameter not in the general case. Returning t as a value would neither keep the padding bits, one exception could have been in theory RVO, but there is no RVO facility in the language, where the value to be returned can be accessed as a lvalue. The language in general may not insert (anymore) any code changing the padding bits and bytes, if there was no write of t. This could have been possible up till now under the as-if rule, as the padding bits may have changed at any time.

Received on 2026-01-23 18:18:43