Issue 164699
Summary Confusing documentation for clang-tidy bugprone-switch-missing-default-case
Labels clang-tidy
Assignees
Reporter 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**.


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to