If the compiler cannot prove that optimizing a call on func does not change the observed behavior of your program, optimizations are not allowed.
Therefore, if the compiler cannot prove that the function call has no observable effect, the call will take place. Note that compilers can sometimes be smart, so if you want to be sure, make sure that the function does have a side effect. (On the other hand, if it’s not, you don’t care.)
This is commonly known as-if .
source share