Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

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

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 line is reportted as:

[+ -] p = new Class; (50% branch coverage)... <-- THIS IS a problem for covering 100% !!!

Can I set any extra options to newer gcc versions in order to report same branch coverage as gcc 4.1 for single lines as "p = new Class;".

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
");
 ...
}

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 !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...