0
 10 [ +  - ][ +  - ] :          2 : Conf::~Conf() {}
  11                 :            : 
  12                 :            : 
  13                 :          2 : Conf::Conf( std::string filename, std::string delimiter,
  14                 :            : std::string comment )
  15 [ +  - ][ +  - ]:          2 :: m_Delimiter(delimiter), m_Comment(comment)
  16                 :            : {
  17                 :            :         // Construct a Conf, getting keys and values from given file
  18                 :            : 
  19 [ +  - ][ +  - ]:          4 :         std::ifstream in( filename.c_str() );
             [ +  - ]
  20                 :            : 
  21 [ +  - ][ -  + ]:          2 :         if( !in ) throw File_not_found( filename ); 
             [ #  # ]
  22                 :            : 
  23         [ +  - ]:          2 :         in >> (*this);
  24                 :          2 : }

The code-coverage report as above. For the class Conf, the hit count of constructor is 2, but the hit count of this line std::ifstream in( filename.c_str() ); is 4 which I think it should be 2 too. How do you think about the different hit count in this code-coverage report, is it a bug of lcov or meaningful?

Usman Kurd
  • 7,212
  • 7
  • 57
  • 86
  • I'm not 100% sure how lcov works, but isn't it counting number of times a function is hit. Since there are two functions on that line, it would have two hits per function? – Mats Petersson Dec 27 '12 at 09:01
  • @MatsPetersson No, I have many such things in my code and it does not do that because of two functions. It's more something to do with branches I think (hence the square brackets). However, indeed, the fact that lcov shows 2 lines in that location is the hint to the double counting. – Alexis Wilke Apr 28 '13 at 23:49

1 Answers1

0

It looks like they are counting two things (there are two lines with square brackets for line 19) and the count must be showing you the total of those two entries. Why the compiler broke up the line in two? That I'm not too sure.

On my end I actually removed the branch counting feature to avoid having to deal with it. It did not seem useful with a large project like I have. Maybe doing so would remove this side effect.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156