-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
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
executionwithout any defined behavior or handlingwithout
handling the value.