在分析以下 main.cpp 文件时,我在“test1 Complete”行中得到“0”,表明当我期望得到“1”时该行尚未执行
主程序
#include <cassert>
#include <iostream>
using namespace std;
void test1() {
cout << "test1 start" << endl;
string pdx;
assert(pdx == "");
cout << "test1 complete" << endl;
}
int main() {
test1();
cout << "Done." << endl;
}
Run Code Online (Sandbox Code Playgroud)
为了分析代码,我使用的脚本是:
#!/bin/bash
clang++ -g -std=c++11 -fprofile-instr-generate -fcoverage-mapping main.cpp
# Execute the program
./a.out
llvm-profdata merge default.profraw -output=merged.profraw
llvm-cov report -show-functions=1 ./a.out -instr-profile=merged.profraw main.cpp
llvm-cov show ./a.out -instr-profile=merged.profraw
rm a.out *.profraw
# $ clang++ --version
# clang version …Run Code Online (Sandbox Code Playgroud)