TuanPM
TuanPM

Reputation: 703

lcov: branches coverage of destructor missing

My working environment

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

Upvotes: 0

Views: 2076

Answers (2)

lbragile
lbragile

Reputation: 8122

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

Upvotes: 0

kingometal
kingometal

Reputation: 31

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.

Upvotes: 3

Related Questions