title: LCOV/GCOV branch coverage with C++ producing branches all over the place
body: <p>We are using LCOV/GCOV to produce test coverage of our projects. Recently we tried to enable branch-coverage additionally. But it looks like, this just doesn't yield the results we expected from a high-level developer view.</p>
  
  <p>Using branch-coverage with C++ blows the report up with branches all over the place. We suspect (as the searching for the issues indicates) that mostly exception handling code creates these "hidden branches". And GCOV/LCOV doesn't seem to skip over these.</p>
  
  <p>I created a small test project to show the problem: <a href="https://github.com/ghandmann/lcov-branch-coverage-weirdness" rel="noreferrer">https://github.com/ghandmann/lcov-branch-coverage-weirdness</a></p>
  
  <p>Currently we use Ubuntu 16.04. with:</p>
  
  <ul>
  <li>gcc v5.4</li>
  <li>lcov &amp; genhtml v1.12</li>
  </ul>
  
  <p>Our production code is built with c++11 enabled. The minimal example isn't built with c++11 enabled, but as we experimented a bit with all different options (c++ standard, optimization, <code>-fno-exceptions</code>) we didn't come up with a passable result.</p>
  
  <p>Anybody got some ideas? Tipps? Are we using anything the wrong way? Is this - as stated somewhere else - really expected behavior?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>As also pointed out on the <a href="https://gcc.gnu.org/ml/gcc-help/2017-02/msg00008.html" rel="noreferrer">gcc-help mailing list</a>, these "hidden branches" occur because of exception handling. So adding the <code>-fno-exceptions</code> switch to gcc produces 100% branch coverage for "simple" programs. But when exceptions are disabled, gcc refuses to compile code which actually uses exceptions (e.g. try-catch, throw). Therefore for real production code this is not an option. Looks like, you have to simply declare ~50% coverage to be the new 100% in this case. ;)</p>