There were already many similar questions asked before:
- Getting useful GCov results for header-only libraries
- Why does gcov report 0% coverage on a header file for a well used class?
- gcov is not generating coverage information for header files
to name just a few. However none of them helped me to resolve my own problem.
I am compiling my source code with gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
g++ -c -pipe -Wno-psabi -std=gnu++11 -Wextra -pedantic -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-inline-small-functions -fno-default-inline -O0 -fno-elide-constructors -g -Wall -W -o .obj/myclass.o unittest_myclass.cpp
I then run gcov (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 on one of my source files with
gcov unittest_myclass.cpp -o .obj/
This file contains unit tests for a header only class. gcov successfully generates coverage information for this header file:
File '../include/myclass.h'
Lines executed:11.05% of 173
Creating 'myclass.h.gcov'
However, the results in myclass.h.gcov are wrong. For most of the lines gcov reports that they dont contain executable code. For those that it detects as executable it reports mostly that they have not been executed. But I am sure that they are being executed (I verified it during debugging, some unit tests fail due to bugs, etc.). No Templates are involved. Therefore I guess that for some reason gcov is unable to detect the correct execution. As you can see from my commandline arguments above: optimization is turned off, inlining is turned off...
Any ideas what else could cause these problems?