0

Please find the below LCOV Report of my code:

  83                 :         84 :   uint8_t a = 0;
  84         [ +  - ]:         84 :   ret = check_uint(section, VALUE, &a);
  85         [ +  + ]:         84 :   if (success != ret) {​
  86 [ +  - ][ +  - ]:          1 :     std::cout << "a read from section. returned Error" << endl;
  87                 :          1 :     return ret;
  88                 :            :   }​

At Line No: 86, (-) not taken its displaying Branch 5 was not taken, but the possibility of ret is 2(success or failure). Anybody can please clarify to me what exactly the mean (Branch 5 was not taken) in lcov branch coverage report?

Ghasem Ramezani
  • 2,683
  • 1
  • 13
  • 32

1 Answers1

2

The short form, is that lcov's interaction with branching, especially with inline calls, can find some of the hidden branches in the code, that are beyond your control.

For example, templated functions (of which std::cout << "foo" is one) can be inlined efficiently by the compiler. Which means that any branches present in that code can also be seen by the compiler. This of course lets the compiler do a more thorough optimization. This is the branch you are seeing here. It's not in code you wrote, but in code the template instantiated for you.

In particular, most formatted output functions on basic_ostream are going to ensure that the stream is in a good state prior to doing the formatting or inserting work.

When I'm doing branch analysis, I tend to disregard branch misses on functions like this. There are several similar places in C++ which branches are detected by gcov/lcov, but are only implementation details. I try to focus on the branches under my control.

Dave S
  • 20,507
  • 3
  • 48
  • 68