This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
bit_cast from volatile behaviour unclearSection: 22.11.3 [bit.cast] Status: New Submitter: Hubert Tong Opened: 2026-10-28 Last modified: 2026-10-31
Priority: Not Prioritized
View other active issues in [bit.cast].
View all other issues in [bit.cast].
View all issues with New status.
Discussion:
From 22.11.3 [bit.cast], it is unclear how std::bit_cast interacts with various
expectations around "volatile access". For example, the std::bit_cast wording does not
identify what access operation is being performed to inspect the object representation
of from. Therefore, it is firstly unclear whether there is any volatile access at all,
and secondly unclear whether there may be multiple volatile accesses (e.g., one per
byte of the object representation).
from in a non-volatile manner or byte-wise are problematic.
This also interacts with the undefined behaviour specified by 7.3.2 [conv.lval]
bullet (3.3) for when lvalue-to-rvalue conversion occurs for an object whose value
representation is not valid for its type. This raises a problem for approaches that try to
access from as a glvalue of its declared type. Such an approach has the additional
problem that the load instructions involved for such a volatile access may not preserve
the value representation, which may be observable by a program if the object was not
actually volatile.
Proposed resolution:
This wording is relative to N5054.
Modify 22.11.3 [bit.cast] as indicated:
template<class To, class From> constexpr To bit_cast(const From& from) noexcept;-1- Constraints:
[…] -?- Mandates:is_volatile_v<From>isfalse. -2- Constant When: NeitherTonorFromhas constexpr-unknown representation (7.7.2 [expr.const.core]).