title: Question about optimization in C++
body: <p>I've read that the C++ standard allows optimization to a point where it can actually hinder with expected functionality. When I say this, I'm talking about return value optimization, where you might actually have some logic in the copy constructor, yet the compiler optimizes the call out.</p>
  
  <p>I find this to be somewhat bad, as in someone who doesn't know this might spend quite some time fixing a bug resulting from this.</p>
  
  <p>What I want to know is whether there are any other situations where over-optimization from the compiler can change functionality.</p>
  
  <p>For example, something like:</p>
  
  <pre><code>int x = 1;
  x = 1;
  x = 1;
  x = 1;
  </code></pre>
  
  <p>might be optimized to a single x=1;</p>
  
  <p>Suppose I have:</p>
  
  <pre><code>class A;
  
  A a = b;
  a = b;
  a = b;
  </code></pre>
  
  <p>Could this possibly also be optimized? Probably not the best example, but I hope you know what I mean...</p>