<p>There's a PR in progress that addresses these limitations. <a href="https://github.com/linux-test-project/lcov/pull/86" rel="noreferrer">https://github.com/linux-test-project/lcov/pull/86</a>.</p>
<p><a href="https://arxiv.org/abs/2008.07947" rel="noreferrer">This paper</a> explains the theory behind the implementation.</p>
<p><a href="https://user-images.githubusercontent.com/471374/99132883-bc70d780-25cc-11eb-84da-4cf92b4bdc69.png" rel="noreferrer"><img src="https://user-images.githubusercontent.com/471374/99132883-bc70d780-25cc-11eb-84da-4cf92b4bdc69.png" alt="Result" /></a></p>
LCOV/GCOV branch coverage with C++ producing branches all over the place
<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>