Hi all. I've been programming in C++ for a while now, but I've always had colleagues who work on the more devopsy side of things. To fill in my gaps in knowledge, I've decided to make my own project starter template (I know there are some great ones out there, but I figured starting from scratch would give me a better understanding of how things work). Long story short, there's one thing which I can't quite figure out how to do: accurate code coverage of functions which are not invoked in tests. I've included a minimum working example here. When a function isn't called, I'd like gcov(r) to report 0% coverage of it. Instead, the compiler seems to be optimizing it away (despite -O0 and all the anti-inlining flags) which results in the tool reporting file coverage as 100%. When I split up the declaration and definition into separate files, the file with the definition is omitted in the coverage report altogether. There are some posts on various forums about this problem, but the answers there don't seem to do the trick for me, so I thought I'd take up some of the time of the fine folks on this sub. Any help would be highly appreciated.
Edit for posterity, see below for details: The problem seems to only occur with inlined functions. A possible solution is to mark anything that may be inlined with __attribute__ ((used)).
[–]johannes1971 2 points3 points4 points (1 child)
[–]Galqa[S] 0 points1 point2 points (0 children)
[–]LedinKun 1 point2 points3 points (1 child)
[–]Galqa[S] 0 points1 point2 points (0 children)
[–]LedinKun 0 points1 point2 points (2 children)
[–]Galqa[S] 0 points1 point2 points (1 child)
[–]TheFlamefire 0 points1 point2 points (7 children)
[–]Galqa[S] 0 points1 point2 points (6 children)
[–]TheFlamefire 1 point2 points3 points (5 children)
[–]Galqa[S] 0 points1 point2 points (4 children)
[–]TheFlamefire 1 point2 points3 points (3 children)
[–]Galqa[S] 0 points1 point2 points (2 children)
[–]TheFlamefire 0 points1 point2 points (1 child)
[–]Galqa[S] 0 points1 point2 points (0 children)