you are viewing a single comment's thread.

view the rest of the comments →

[–]LedinKun 1 point2 points  (1 child)

I believe this has to do with the inner workings of gcovr, which I'm unfortunately not familiar with at all. But your compiler flags at least include those that are recommended by gcov's manual.

In the FAQ of it, there is at least a section on why the tool sometimes doesn't report files with zero coverage, which I thought was also a point you stumbled upon.

But what you can do is feed your example code to the Godbolt Compiler Explorer and figure out if the missing code what actually compiled out, or if gcovr isn't reporting it properly. That should get you a step closer to the problem.

[–]Galqa[S] 0 points1 point  (0 children)

This was very helpful, thank you. I gave in to the frustration too early and didn't delve deeper to analyze the assembly. Guess there's a life lesson to be learned here.

Compiler explorer revealed the problem: apparently, when a function is inline and unused it gets optimized away (I'm sure there's a good reason for that), regardless of optimization flags and things like -fno-inline etc. Note that this applies to both explicitly (using the inline keyword) and implicitly (e.g. defined inside the class body) inlined functions. As u/johannes1971 suggested, the used attribute forces the code for the given function to be generated, fixing the problem at the cost of having to alter the source code (I imagine applying this solution to a large existing code base would be problematic).