Skip to content

bugprone-switch-missing-default-case false positives #165623

@nick-potenski

Description

@nick-potenski

The bugprone-switch-missing-default-case checker can present false positive findings when a switch's case statement is logically complete even though the switch does not use an enum value.

For example:

int foo(unsigned int in) {
    switch (in % 4) {
        case 0:
        case 1:
        case 2:
        case 3:
            return 1;
    }

    return 0;
}

yields

warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
    3 |     switch (in % 4) {
      |     ^
1 warning generated.

Compiler explorer link.

FWIW, I understand that the checker's documentation specifically states that it is only looking for the intersection of non-enum switches and missing default cases, so I can understand why my report may be out of scope. It won't hurt my feelings if you want to reject this or file it as an improvement rather than a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions