Skip to content

Confusing documentation for clang-tidy bugprone-switch-missing-default-caseΒ #164699

@Keith-S-Thompson

Description

@Keith-S-Thompson

The documentation for clang-tidy's "bugprone-switch-missing-default-case" option is confusing, incorrectly suggesting undefined behavior.

The following appears in clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst:

Switch statements without a default case can lead to unexpected
behavior and incomplete handling of all possible cases. When a switch statement
lacks a default case, if a value is encountered that does not match any of the
specified cases, the program will continue execution without any defined
behavior or handling.

The last sentence suggests that if no case is matched, the behavior is undefined. In fact, the behavior is well defined by the C standard, and the switch statement simply does nothing in these circumstances.

This documentation appears here: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/switch-missing-default-case.html.

Suggested fix:

Switch statements without a default case can lead to unexpected
behavior and incomplete handling of all possible cases.
When a switch statement lacks a default case, if a value is
encountered that does not match any of the specified cases, the
switch statement will do nothing and
the program will continue
execution without any defined behavior or handling without
handling the value
.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions