gcov and C++'s global destructors
Sven C. Koehler
schween@snafu.de
Fri Jan 11 05:53:00 GMT 2002
Hello all!
I am trying to use gcov in conjunction with unit testing to find out
which lines of code were not yet covered by the tests. Alas, I found out
that those lines that were called by destructors of global variables
were assumed to be not executed at all. Example code is appended.
My GCC version is: gcc version 2.95.3 20010315 (SuSE) on Intel.
Does someone know how to make this work? I didn't find something in the
documentation or mailing list archives concerning this issue.
TIA & Best Regards,
Sven C. Koehler
Example Code:
[test.cpp]
#include <iostream>
class TestClass {
public:
TestClass() { std::cout << "ctor" << std::endl; }
~TestClass() { std::cout << "dtor" << std::endl; }
};
TestClass test;
int main(int argc, const char* argv[]) {
std::cout << "in main()" << std::endl;
}
Compile:
%g++ -O0 -ftest-coverage -fprofile-arcs -o test test.cpp
Execution yields:
%./test
ctor
in main()
dtor
Invoking gcov:
%gcov test.cpp
80.00% of 5 source lines executed in file test.cpp
Showing lines that were not executed:
%grep '######' test.cpp.gcov
###### ~TestClass() { std::cout << "dtor" << std::endl; }
-> Which is wrong as we can see from the output of the execution.
More information about the Gcc
mailing list