Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch issue #71

Closed
johvik opened this issue Oct 28, 2014 · 1 comment
Closed

switch issue #71

johvik opened this issue Oct 28, 2014 · 1 comment
Labels

Comments

@johvik
Copy link

johvik commented Oct 28, 2014

With the following code I expect to get 100% branch coverage:

#include <stdio.h>

void do_switch(int len) {
    switch (len & 1) {
        case 1:
            printf("one\n");
            break;
        case 0:
            printf("zero\n");
            break;
    }
}

int main() {
    do_switch(1);
    do_switch(0);
    return 0;
}

But it claims that I missed one branch.

Changing case 0: to default: gives the expected results.

@latk
Copy link
Member

latk commented Dec 28, 2017

Gcovr does not understand your code, it just reports coverage results. So if your compiler with the optimizations you have chosen emits an extra fall-through branch because it cannot recognize that one of the cases must apply, that's an issue with the compiler and not with gcovr.

Note that gcc/gcov thinks about coverage in terms of machine code instructions, not in terms of language-level control flow constructs. The coverage results tend to get confused with inlined functions, optimizations, and C++ destructors.

@latk latk closed this as completed Dec 28, 2017
@latk latk added the wontfix label Dec 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants