GCC Code Coverage Report


Directory: .
File: main.cpp
Date: 2025-09-27 21:24:05+00:00
Coverage Exec Excl Total
Lines: 95.2% 20 23 44
Functions: 100.0% 7 5 12
Branches: 68.8% 11 12 28
Conditions: 87.5% 7 8 16

Line Branch Condition Exec Source
1 #include <iostream>
2
3 #if defined USE_LAMBDA
4 # include <algorithm>
5 # include <array>
6 # include <functional>
7 #endif
8
9 int /* GCOVR_EXCL_FUNCTION */ foo(int param) { // GCOVR_EXCL_FUNCTION
10 if (param) {
11 param++;
12 } else {
13 param--;
14 }
15
16 return param;
17 }
18
19 1 int bar(int param) { // Excluded by CLI option
20
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 1 time.
1/2
✗ True not covered.
1 if (param) {
21 param++;
22 } else {
23 1 param--;
24 }
25 1 return param;
26 }
27
28 #if defined USE_LAMBDA
29 #define LAMBDA_SORT \
30 { \
31 std::array<int, 10> arr = { 0, 9, 1, 8, 2, 7, 3, 6, 4, 5 }; \
32 std::sort( \
33 std::begin(arr), \
34 std::end(arr), \
35 [](int a, int b) { \
36 if (a > b) \
37 return true; \
38 return false; \
39 } \
40 ); \
41 }
42
43 // Function in line with exclude
44
3/4
sort_excluded():
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 13 not taken.
sort_excluded()::{lambda(int, int)#1}::operator()(int, int) const:
✓ Branch 2 → 3 taken 25 times.
✓ Branch 2 → 4 taken 16 times.
2/2
✓ Fully covered.
44 void sort_excluded(void) /* GCOVR_EXCL_FUNCTION */ { LAMBDA_SORT /* THIS is not excluded*/
45
3/4
sort_excluded():
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 14 not taken.
sort_excluded()::{lambda(int, int)#2}::operator()(int, int) const:
✓ Branch 2 → 3 taken 25 times.
✓ Branch 2 → 4 taken 16 times.
2/2
✓ Fully covered.
44 LAMBDA_SORT
46 }
47
48 1 void sort_lambda_excluded(void)
49 {
50
3/4
✓ Branch 2 → 3 taken 25 times.
✓ Branch 2 → 4 taken 16 times.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 13 not taken.
2/2
✓ Fully covered.
44 LAMBDA_SORT // GCOVR_EXCL_FUNCTION not working because after function definition
51
52 1 std::array<int, 10> arr = { 0, 9, 1, 8, 2, 7, 3, 6, 4, 5 };
53
54
1/2
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 14 not taken.
2 std::sort(
55 std::begin(arr),
56 std::end(arr),
57 [](int a, int b) { // GCOVR_EXCL_FUNCTION
58 if (a > b)
59 return true;
60
61 return false;
62 }
63 );
64 1 }
65
66 void sort_excluded_both(void) // GCOVR_EXCL_FUNCTION
67 {
68 std::array<int, 10> arr = { 0, 9, 1, 8, 2, 7, 3, 6, 4, 5 };
69
70 std::sort(
71 std::begin(arr),
72 std::end(arr),
73 [](int a, int b) { // GCOVR_EXCL_FUNCTION
74 if (a > b)
75 return true;
76
77 return false;
78 }
79 );
80
81 std::sort(
82 std::begin(arr),
83 std::end(arr),
84 [](int a, int b) { // Excluded by CLI option
85 if (a > b)
86 return true;
87
88 return false;
89 }
90 );
91 }
92 #endif
93
94
95 1 int main(int argc, char* argv[]) {
96 1 foo(0);
97 1 bar(0);
98 #if defined USE_LAMBDA
99 1 sort_excluded();
100 1 sort_lambda_excluded();
101 1 sort_excluded_both();
102 #endif
103 1 return 0;
104 }
105