This project is read-only.

Coverage count of unused functions

Jun 22, 2016 at 3:07 PM
I see an issue with the coverage of unused functions in a cpp file.
In verbose mode the "Executable lines" for these functions are missed.

From my point of view this is an issue. I expected unused function lines are added to the uncovered lines count.
See, I have very large cpp-files under unit testing and want to use the coverage report to determine, which functions have been tested and which are not.
Jun 27, 2016 at 9:50 PM

OpenCppCoverage uses pdb files to track functions coverage. If you are able to put a breakpoint in your function, OpenCppCoverage should be able to list the executable lines.

  • In release mode, unused functions are removed from the binary by default.
  • There is a special case for unused inline function: See here for more information.
Are you in one of the previous case?
Are you able to put correctly a breakpoint in your function?

If this does not help, can you sent me the file so that I can reproduce and debug it?

Hope that help,

Jun 28, 2016 at 7:18 AM
Edited Jun 28, 2016 at 12:59 PM

I'm not in one of the two cases you listed.

BUT: I'm not able to put a breakpoint to the functions I'm missing. Message while debugging is: "The breakpoint will not currently be hit. No executable code of the debugger's target code type".
So I think this is the reason for the missing "Executable lines". I disabled all compiler optimization and tried different compiler and linker flag with no success.

I see, this is not a bug. Anyway I'm unsatisfied with this behavior. In my current situation with a large bunch of untested c++ code, OpenCppCoverage gives me a wrong indication about untested (uncovered) and tested (covered) code.

With your knowledge about code coverage: Do you have an idea how to track the "not executable lines" of code and add them to the count of uncovered lines?


After brainstorming with my colleague we found a workaround for my problem. It's ugly but it works.
I created a test class named ForCorrectCoverageOnly with one test method named doItForTheCoverage. In this method I call all uncovered functions from an if statement that will always be true and can't get optimized by the compiler.
if (!time(0))
     uncoveredFunction1(0, 0);
Anyway this is just a workaround and I don't like this solution. So my question to you is still relevant.

Thanks and regards
Jun 30, 2016 at 8:39 PM

I noticed "if (!time(0))" and "can't get optimized by the compiler.". It is not needed in a debug build. Can you check you have /Od in C++ settings (no optimization) and /OPT:NOREF in linker settings (Do not remove unused functions).

Another explanation is that your function is template.

If it does not help, can you provide a simple example of your problem? OpenCppCoverage detects "normal" functions that are not called as you can see here.

Let me know if you find something,

Marked as answer by OpenCppCoverage on 8/20/2016 at 8:11 AM