title: What's the best g++ optimization level when building a debug target?
body: <p>When you want to build something that's debuggable (g++ specifically, but perhaps shares an answer with gcc), what's the best -O level?  In other words, when building a "debug" target rather than a "release" target.</p>
  
  <p>The gcc online docs are a little sketchy when comparing -O0 and -O1 (<a href="http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html" rel="noreferrer">here</a>).  My interpretation is that -O1 only enables one optimization that even may affect debugability, which is -fomit-frame-pointer.  But to quote the doc, it's only enabled in -O1 "where doing so does not interfere with debugging."  Am I interpreting that correctly?</p>
  
  <p>Another post on this site (<a href="https://stackoverflow.com/questions/4692592/using-g-and-o2-options-in-gcc">here</a>) talks about -O2 specifically, and the answer is basically "it works but you get out-of-order execution".  Which, IMO, can range from annoying to devastating depending on how badly things jump around.</p>