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.

4377. Misleading note about lock-free property of std::atomic_ref

Section: 32.5.7.2 [atomics.ref.ops] Status: New Submitter: Brian Bi Opened: 2025-09-15 Last modified: 2025-09-20

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:

Note 1 to 32.5.7.2 [atomics.ref.ops] states:

Hardware could require an object referenced by an atomic_ref to have stricter alignment (6.8.3 [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.

Proposed resolution:

This wording is relative to N5014.

  1. Modify 32.5.7.2 [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 (6.8.3 [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]