Skip to content

[clang-tidy] Check request: readability-use-switch-statement #133322

@denzor200

Description

@denzor200

Needs a check that will find a chained if-else statement and suggest to change it to use switch-statement.

BEFORE:

if (i == 1) {
    std::cout << "first" << std::endl;
} else if (i == 2) {
    std::cout << "second" << std::endl;
} else if (i == 3) {
    std::cout << "third" << std::endl;
}

AFTER:

switch (i) {
case 1:
    std::cout << "first" << std::endl;
    break;
case 2:
    std::cout << "second" << std::endl;
    break;
case 3:
    std::cout << "third" << std::endl;
    break;
default:
    break;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions