我最近升级到了新版本的 gcc/g++/gcov,现在 gcov 的行为很奇怪。新版本声称未涵盖旧版本中涵盖的某些代码行。我设法将我的代码减少到这个最小的示例。
#include <memory>
using namespace std;
struct S {};
int main() {
unique_ptr<S> s;
s = make_unique<S>();
}
Run Code Online (Sandbox Code Playgroud)
然后我使用 编译此文件g++ -O0 -Wall -Wextra -Werror --std=c++17 --coverage,运行结果a.out,然后运行gcov。
生成的.gcov文件包含:
-: 0:Runs:1
-: 1:#include <memory>
-: 2:using namespace std;
-: 3:struct S {};
-: 4:
1: 5:int main() {
#####: 6: unique_ptr<S> s;
1: 7: s = make_unique<S>();
1: 8:}
Run Code Online (Sandbox Code Playgroud)
这与 gcov 的旧版本不同,旧版本声称第 6 行被命中了 2 次。
为什么 gcov 认为第 6 行没有被覆盖?难道我做错了什么? …
我想使用与系统默认不同的 gcc 来构建项目。因此我需要为 lcov 提供正确的 gcov-tool 版本。不幸的是,该--gcov-tool标志对我不起作用。即使 lcov 应该默认的版本也不行。
示例运行:
############## extract test coverage ##############
g++-8 (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gcov-tool-8 (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. …Run Code Online (Sandbox Code Playgroud) 起初我接受消息 sample.gcda:stamp mismatch with graph file
hexdump -e '"%x\n"' -s8 -n4 sample.gcno-> aaa1aaaa-
hexdump -e '"%x\n"' -s8 -n4 sample.gcda> bbb2bbbb