[clang-tidy] Add check for possibly incomplete switch statements
authorShivam Gupta <Shivam.Gupta2@amd.com>
Sun, 16 Jul 2023 16:43:55 +0000 (22:13 +0530)
committerShivam Gupta <Shivam.Gupta2@amd.com>
Mon, 17 Jul 2023 05:10:11 +0000 (10:40 +0530)
commit42179bbf6bcc9f90256b443c30f5e99f862bc2f6
treec87cfa4df75f0a0c2cbf17aee1367d86152641f0
parent7ce4e933eab28d7a6b7a54ef96bee8853cc30bbc
[clang-tidy] Add check for possibly incomplete switch statements

While clang warns about a possibly incomplete switch statement when switching over an enum variable and failing to cover all enum values (either explicitly or with a default case), no such warning is emitted if a plain integer variable is used as switch variable.

Add a clang-tidy check to diagnose these scenarios.

No fixit hint is provided since there are multiple possible solutions.

Differential Revision: https://reviews.llvm.org/D4784
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/bugprone/SwitchMissingDefaultCaseCheck.h [new file with mode: 0644]
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst [new file with mode: 0644]
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/switch-missing-default-case.cpp [new file with mode: 0644]