
[英]Why does gcov report 0% coverage on a header file for a well used class?
[英]Why does gcov report in-class function definitions as not executable?
似乎gcov并未将类方法的内联定义报告为可执行行。 例:
#include <iostream>
struct Foo {
void bar() {}
void baz() {}
};
int main() {
Foo foo;
foo.bar();
}
如果我使用g++ -g -O0 -ftest-coverage -fprofile-arcs -o main main.cpp
编译上述程序,运行它,并在其上调用gcov,则会得到以下报告:
-: 0:Source:main.cpp
-: 0:Graph:main.gcno
-: 0:Data:main.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include <iostream>
-: 2:
-: 3:struct Foo {
1: 4: void bar() {}
-: 5: void baz() {}
-: 6:};
-: 7:
1: 8:int main() {
-: 9: Foo foo;
1: 10: foo.bar();
4: 11:}
为什么即使将上述方法正确地报告为已执行一次,第5行仍被报告为不可执行?
更新
根据gcov的文档( https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html#Invoking-Gcov ), -
表示非可执行行而#####
和====
标记可以执行但不能执行的行。
gcov报告说,链接您的二进制文件后 ,就永远不会有Foo::baz()
被执行的可能性。
链接器完全删除了该功能,因此不再有可执行文件与该行关联。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.