Tags: Programming Language.
In general the C++ standard allows a compiler to perform any optimization provided the resulting executable exhibits the same observable behaviour as if i.e. pretending all the requirements of the standard have been fulfilled. This is commonly referred to as the as-if rule.