Considering following array and two series of assignments:
char charArray[3];
charArray[0]='a';
charArray[1]='b';
charArray[2]='c';
char & charRef1=charArray[0];
charRef1='a';
char & charRef2=charArray[1];
charRef2='b';
char & charRef3=charArray[2];
charRef3='c';
Does C++ standard dictate whether these two series of assignments should be implemented identically or differently by the compiler?
No, the standard makes no requirements that the implementation details must be the same. 1.9/1:
So only the “observable behavior” has to be the same. Observable behavior is defined in 1.9/6:
The exact instructions used to achieve this are not “observable behavior”, and in your example since the array is not
volatile, the order of writes isn’t observable either. In fact, unless you use the array later, the writes themselves aren’t observable. It would be legal for the implementation’s optimizer to successfully remove the entire code snippet in one case but not the other, although perhaps surprising that it could manage only one.