简体   繁体   English

lcov:缺少析构函数的分支覆盖

[英]lcov: branches coverage of destructor missing

My working environment我的工作环境

  • cygwin赛格温

  • lcov 1.13液晶显示器 1.13

  • GCC 5.4.0海湾合作委员会 5.4.0

Problem is coverage report in html told that missing branch in destructor but the destructor is empty.问题是 html 中的覆盖率报告告诉析构函数中缺少分支,但析构函数为空。 I don't know why.我不知道为什么。 Anyone can help me ?任何人都可以帮助我吗? I also try with GCC 4.8.0 but same result我也尝试使用 GCC 4.8.0 但结果相同在此处输入图片说明

I had the same problem and I found this on stackoverflow .我遇到了同样的问题,我在 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.然后应该调用两种类型的析构函数。

A simple solution is to add // GCOVR_EXCL_LINE as a comment to your line that you know is not executing both branches.一个简单的解决方案是将// GCOVR_EXCL_LINE添加为您知道不会执行两个分支的行的注释。 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.我认为在这种情况下这是一个好主意,因为根据我的理解,没有另一种方法可以强制 GCOV 同时采用析构函数的动态和非动态分支。

For example:例如:

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

will exclude the delete a;将排除delete a; line from the coverage report.行从覆盖率报告。

See the following for more details: https://gcovr.com/en/master/guide.html#exclusion-markers有关更多详细信息,请参阅以下内容: https : //gcovr.com/en/master/guide.html#exclusion-markers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM