c++11 order of evaluation confusion
08:48 01 Apr 2026

I've read several topics about c++11 regarding the order of evaluation including How to determine what is 'sequenced before' others? but still there are some aspects of the standard that I do not feel confident.

The following example is from https://en.cppreference.com/w/cpp/atomic/memory_order.html where it explains relaxed ordering.

relaxed_ordering_example

I am aware of compiler re-ordering, the question is not about it. It says that C is sequenced before D and also says that D is completed (obviously with its side effect on y) before C.

What sequenced before is described at https://en.cppreference.com/w/cpp/language/eval_order.html

sequenced_before_2011

From the above explanation I understand the following:

  • Evaluation of expressions does not say anything about the completion of side effects, only initiation of them is mentioned (c++ standard prior to c++11 had the term sequence point where it included the completion of side effects)

  • If C is sequenced before D, then the evaluation of C completes before the evaluation of D, which means the value computation and side effect initiation (not completion) of C is completed before the value computation and side effect initiation of D.

What I conclude from all the above is:

  • C sequenced before D does not imply that all side effects of C are completed before D.

Question 1: Is the above deduction true? If so, what would happen when we compile our legacy, pre-c++11 codes with a c++11 (or later) compiler. Those codes were written with the safety of sequence point existence.

Now let me go back to the original example: "C is sequenced before D but D is completed before C"

// Thread 1:
r1 = y.load(std::memory_order_relaxed); // A
x.store(r1, std::memory_order_relaxed); // B
// Thread 2:
r2 = x.load(std::memory_order_relaxed); // C 
y.store(42, std::memory_order_relaxed); // D

According to sequenced before rules I think the order is as follows:

  1. value computation of C is done

  2. side effect initiation of C (obviously one of them is the modification of r2)

  3. value computation of D

  4. side effect initiation of D (obviously one of them is the modification of y)

If D is completed before C it means modification of y is completed before modification of r2 which means the completion of side effects in #4 occurred before the completion of side effects in #2

But #1 is the first thing to do per sequenced before rules: "Value computations: calculation of the value that is returned by the expression C"

https://en.cppreference.com/w/cpp/language/eval_order.html states some rules about sequencing

ordering_rules_2011

8)The side effect (modification of the left argument) of the built-in assignment operator and of all built-in compound assignment operators is sequenced after the value computation (but not the side effects) of both left and right arguments, and is sequenced before the value computation of the assignment expression (that is, before returning the reference to the modified object). In item #8, it describes a sequencing order for assignment in the following order:

  1. value computation (but not the side effects) of both left and right arguments

  2. the side effect (modification of the left argument)

  3. value computation of the assignment expression

Question 2: Does not the above order is contradicting with the order explained for evaluations of expressions, i.e. first compute the value of the expression and then initiate the side effect?

c++ c++11 memory-barriers stdatomic happens-before