0

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

TuanPM
  • 685
  • 8
  • 29

2 Answers2

3

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.

Community
  • 1
  • 1
kingometal
  • 31
  • 3
  • I created the object as "TestClass b;" The destructor already called but it missing branches – TuanPM Feb 24 '17 at 02:10
0

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

lbragile
  • 7,549
  • 3
  • 27
  • 64