4

I'm using Ubuntu 12, g++ and lcov, the latter installed with apt-get install lcov.

I'm successfully compiling, and generating html reports with genhtml. The line coverage information looks good, but many of the function coverage counts seem odd. For example, one C++ class containing just a constructor and virtual destructor is reported by lcov as having 7 functions. Therefore, my coverage is only 2/7 if I call both during the session.

Here is an example output which shows a class with one function that never gets called. I can't work out what that function is:

example output

Can anyone decode the mangled function name, explain the inflated function counts, and suggest how to go about resolving the problem?

Thanks in advance.

Update

OK, since answering my original question below (see comments), I am now inviting suggestions as to how I can prevent these under-the-hood ctors and dtors corrupting my function coverage statistics. How can I limit the function counts to those functions I've written myself?

drb
  • 45
  • 1
  • 5
  • 4
    OK, a bit more digging around, and the use of the `c++filt` command to un-mangle the names, helped me solve this one. The answer relates to auto-generated constructors and destructors. Under the hood, there are many more than I realized. See a good explanation [here on StackOverflow](http://stackoverflow.com/questions/6613870/gnu-gcc-g-why-does-it-generate-multiple-dtors). – drb Jul 11 '12 at 02:44
  • 1
    You should provide this as an answer instead of a comment. – dbn Apr 05 '13 at 23:35

1 Answers1

1

I suppose you are on a new project by now, and at the time you may not have been using C++11, but if you do that now maybe this will help:

class my_class
{
    ...
    my_class(my_class const &) = delete;
    ...
};

This also means you have to have some form of declaration for all the possible default constructors that you do not want to have... Now if you are using the default constructors, then you probably need to enhance your tests because lcov is telling you that you are actually not testing them! Something of the sort should do:

my_class a;
my_class b(a);
my_class c;
c = b;
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
  • Alexis, Thank you! I am indeed on another project now, but I still appreciate your response. Your comment about the default constructors not being tested is a great observation. – drb May 30 '14 at 23:23