Created on 2025-09-15.00:00:00 last changed 3 weeks ago
Proposed resolution:
This wording is relative to N5014.
Modify [atomics.ref.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)`.
-2- [Note 1:Hardware could require an object referenced by an `atomic_ref` to have stricter alignment ([basic.align]) than other objects of type `T`. Further, whether operations on an `atomic_ref` are lock-free could depend on the alignment of the referenced object. For example, lock-free operations on std::complex<double> could be supported only if aligned to `2*alignof(double)`An implementation can choose to define atomic_ref<T>::required_alignment to a value greater than `alignof(T)` in order to ensure that operations on all objects of type atomic_ref<T> are lock-free. — end note]
Note 1 to [atomics.ref.ops] states:
Hardware could require an object referenced by an `atomic_ref` to have stricter alignment ([basic.align]) than other objects of type `T`. Further, whether operations on an `atomic_ref` are lock-free could depend on the alignment of the referenced object. For example, lock-free operations on std::complex<double> could be supported only if aligned to `2*alignof(double)`.
By using the word "Further", the note misleadingly implies that `required_alignment` may need to be greater than `alignof(T)` even before considering lock freedom, i.e., that std::atomic_ref<T> may be completely unimplementable on given hardware if the stricter alignment requirement is not met. However, that can never be true because falling back to a lock-based implementation is always possible.
The note could also be misinterpreted to imply that even though an object may be aligned to `required_alignment` and thus referenceable by an `atomic_ref`, operations could still fail to be lock-free because there is a stricter alignment requirement that the object does not meet. Such an interpretation is, however, at odds with p4. The example given by the note is also confusing in that it does not necessarily demonstrate a situation in which std::atomic_ref<T>::required_alignment is greater than `alignof(T)`. In conclusion, this note appears to be a convoluted way of saying that, in order to ensure that operations on atomic_ref<T> are lock-free, the implementation may define `required_alignment` to a value greater than `alignof(T)`. The note should be modified to say this much more clearly.History | |||
---|---|---|---|
Date | User | Action | Args |
2025-09-20 17:10:07 | admin | set | messages: + msg15070 |
2025-09-15 00:00:00 | admin | create |