79649893

Date: 2025-06-02 15:06:26
Score: 0.5
Natty:
Report link

Firstly, your goal of detecting unreachable code with gcovr doesn't seem useful. The execution count of unreachable code is trivially zero.

Using gcov (the text-based output and backend for gcovr), we can generate a file with the source code with an execution count next to each line. If a line is never executed it is shown as "#####". If it is not executable (whitespace, comments, a single brace, etc.) it is shown as "-".

Your first unreachable code segment (in the ifdef) is shown as not executable as there is no code generated from it. The pre-processor prunes this away before compilation so it may as well not exist as far as the compiler is concerned. It gets a dash.

Your second unreachable function (after returning) is removed by the compiler even at -O0 in my testing. This means the line is not executable and gcov gives it a dash.

The definitions of foo and bar will generally be kept by the compiler in case other compilation units need it. Even if it is not needed, as long as it generates some instruction at compilation, gcov can track it. So it will get an execution count.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Luke Sharkey