I'm using GCC 4.9 with GCOV to get code and branch coverage. However, the results for branch coverage are utterly useless for my C++ code. It seems GCC inlines templates despite using all -fno-*-inline
flags I know of.
Here is a small example application that illustrates the problem:
#include <string>
#include <iostream>
using namespace std;
int main() {
string foo;
foo = "abc";
cout << foo << endl;
}
I compile the program with g++ -O0 -fno-inline -fno-inline-small-functions -fno-default-inline --coverage -fprofile-arcs test.cpp -o test
After running test
, gcovr -r . -b
prints:
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File Branches Taken Cover Missing
------------------------------------------------------------------------------
test.cpp 14 7 50% 7,8,9,10
------------------------------------------------------------------------------
TOTAL 14 7 50%
------------------------------------------------------------------------------
There is not a single branch in our main
function. For example, line 7 contains string foo;
. It seems the constructor of std::basic_string<...>
has some if statement in it, but that's not useful information when looking at the coverage of main
.
The problem is that all these inlined branches sum up and the branch coverage calculated for my actual unit tests are about 40% as a result. I'm interested in the branch coverage of my code, as opposed to how much branches I hit in the C++ standard library.
Is there any way to completely shut down inlining in the compiler or to tell GCOV to not consider inlined branches? I couldn't find any guide on the GCOV homepage or someplace else regarding that topic.
Any help is much appreciated.