gcovr/gcovr — pull request #20 by piotrdz (2013-10-24 18:43:46+00:00)
Title: Option to exclude unreachable branches

I have recently come across a problem described in this StackOverflow question:
http://stackoverflow.com/questions/7199360/what-is-the-branch-in-the-destructor-reported-by-gcov

Basically, there are cases where compiler will insert hidden generated code that is essentially dead in the sense that it cannot be fully exercised by test suites. As it is generated code, we shouldn't care about it, but it shows uglily on branch coverage report generated by gcovr. It is confusing for those that are not aware of this issue and makes it difficult to analyze coverage in a large project with many files and thousands of lines of code.

I decided to add new option '--exclude-unreachable-branches' to gcovr to attempt to find and exclude such lines from coverage. In my implementation, branches can be excluded from coverage in these two cases:
* in line of code they were reported, there are only "empty" statements: '{', '}', '{}' (stripping comments and whitespace) - therefore it must be code generated by the compiler
* they are in range of lines marked with GCOV/LCOV exclude markers - this allows to specify additional places which we want to exclude where automatic detection would fail

I have tested the code on several small and large projects and I do not think that there should be any false positives. GCOV/LCOV exclude patterns work as well.

There is only one case where my code fails: if gcov fails to find source file and generates gcov output with lines of code as "/* EOF */". I would like to have a better fallback mechanism in such case but I do not know how to get around this.