Title
Clarify whether an atomic operation is the function call expression or an evaluation within the invocation
Status
new
Section
[atomics.types.operations]
Submitter
jim x

Created on 2026-11-30.00:00:00 last changed 5 days ago

Messages

Date: 2026-11-30.00:00:00

Consider the following example:

#include <atomic>

int main() 
{
  std::atomic<int> value = 1;
  auto r = value.load() + value.load();
}

In this example, it is intuitively expected that the two atomic load operations are indeterminately sequenced with respect to each other, rather than being unsequenced.

The intended rule to establish this ordering is [intro.execution] p12:

For each function invocation F, each evaluation that does not occur within F […] is either sequenced before all evaluations that occur within F or sequenced after all evaluations that occur within F; […]

However, according to [intro.execution] p10:

Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced.

The function call expressions themselves (the two instances of `value.load()`) are subexpressions of the operands of the `+` operator. A function call expression does not occur within the function invocation it initiates.

If the "atomic operation" (the actual memory load) is interpreted as the evaluation of the function call expression itself, [intro.execution] p12 would not apply between the two loads, leaving them formally unsequenced under [intro.execution] p10.

Conversely, if the atomic operation is understood to be a hypothetical evaluation that occurs within the function body of the invoked function, then [intro.execution] p12 successfully orders the evaluations occurring within the first invocation relative to those in the second invocation, making them indeterminately sequenced.

Since standard library atomic operations are often implemented via compiler intrinsics/builtins, the current wording in [atomics.types.operations] does not make it sufficiently clear whether the effects (the atomic read/write) constitute evaluations occurring within a function invocation.

Suggested Resolution:

Clarify in [atomics.types.generic.general] (or [atomics.types.operations]) that an atomic operation is modeled as an evaluation (or a set of evaluations taken as a whole) occurring within the corresponding function invocation, ensuring that [intro.execution] p12 guarantees they are indeterminately sequenced when invoked within unsequenced subexpressions.

History
Date User Action Args
2026-11-30 00:00:00admincreate