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.
atomic_ref<cv T>::required_alignment should be the same as for TSection: 32.5.7.2 [atomics.ref.ops] Status: New Submitter: Jonathan Wakely Opened: 2025-11-06 Last modified: 2025-11-06
Priority: Not Prioritized
View other active issues in [atomics.ref.ops].
View all other issues in [atomics.ref.ops].
View all issues with New status.
Discussion:
When P3323R1 fixed support for atomic_ref<cv T>
we didn't consider that an implementation could define required_alignment
to be different from atomic_ref<T>::required_alignment.
For example, a processor could support atomic loads on any int object,
but could require a greater alignment for atomic stores (and read-modify-write
and modify-write operations).
So the required_alignment could be alignof(int) for const int
but 2 * alignof(int) for int, because the latter is needed for stores.
A malicious implementation could even define required_alignment to be
greater for the const T specialization, which would make it undefined
to use the new converting constructor added by P3860R1.
We should constrain implementations to use the same required_alignment
for cv T, so that users can use atomic_ref<const T>
on any object that is referenced by a atomic_ref<T>.
Proposed resolution:
This wording is relative to N5014.
Modify [atomics.refs.ops], as indicated:
static constexpr size_t required_alignment;-1- The alignment required for an object to be referenced by an atomic reference, which is at least
alignof(T). The value ofatomic_ref<cv T>::required_alignmentis the same asatomic_ref<T>::required_alignment-2- [Note 1: Hardware could require an object referenced by an
atomic_refto have stricter alignment (6.8.3 [basic.align]) than other objects of typeT. Further, whether operations on anatomic_refare lock-free could depend on the alignment of the referenced object. For example, lock-free operations onstd::complex<double>could be supported only if aligned to2*alignof(double). — end note]