Why gcc 4.1 + gcov reports 100% branch coverage and newer (4.4, 4.6, 4.8) reports 50% for “p = new class;” line?

前端 未结 2 907
北海茫月
北海茫月 2020-12-01 15:11

When gcc 4.1 (using gcov) next line:

p = new Class;

is reported as 100% branch coverage <-- THIS IS OK for me.

Why using gcc 4.4 and higher same l

相关标签:
2条回答
  • 2020-12-01 15:51

    Another solution would be to use --exclude-throw-branches if you are running gcovr. For example:

    gcovr --exclude-throw-branches ...
    

    This allows you to still throw exceptions in your code but exclude all exception generated branches. More on this in gcovr FAQ

    0 讨论(0)
  • 2020-12-01 15:55

    Solved !

    We have some C/C++ files with and without exceptions handling, so lcov/gcov process "exceptions handling" for each code block.

    Inside a normal block, for example:

    int main(void)
    {
     ...
     ...
     [+ -] printf("Hello\n");
     ...
    }
    

    gcov reports that printf line has a "branch coverage" of 50% ---> WHY ?

    Because exceptions handling is enabled !!!

    In order to solve this issue, specify:

    -fno-exceptions

    in g++ command line.

    Example:

    g++ -O0 --coverage -fno-exceptions -fno-inline ....

    Thanks !

    0 讨论(0)
提交回复
热议问题