lcov: branches coverage of destructor missing

1.7k views Asked by At

My working environment

  • cygwin

  • lcov 1.13

  • GCC 5.4.0

Problem is coverage report in html told that missing branch in destructor but the destructor is empty. I don't know why. Anyone can help me ? I also try with GCC 4.8.0 but same result enter image description here

2

There are 2 answers

1
kingometal On

I had the same problem and I found this on stackoverflow. The short answer is that there are different types of destructors, depending on whether you delete a dynamically allocated object, or is a statically allocated object destructed.

So to get rid of this missing branch coverage, you have to create an object with

TestClass* a = new TestClass();

and

TestClass b;

and then make sure, they are both destroyed, the former, of course, with

delete a;

Then both types of destructor should be called.

0
lbragile On

A simple solution is to add // GCOVR_EXCL_LINE as a comment to your line that you know is not executing both branches. I think this is a good idea for this case, as from my understanding there isn't another way to force GCOV to take both dynamic and non-dynamic branches of the destructor.

For example:

TestClass *a = new TestClass;
delete a; // GCOVR_EXCL_LINE

will exclude the delete a; line from the coverage report.

See the following for more details: https://gcovr.com/en/master/guide.html#exclusion-markers