CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
57 lines
1.8 KiB
ReStructuredText
57 lines
1.8 KiB
ReStructuredText
.. title:: clang-tidy - bugprone-switch-missing-default-case
|
|
|
|
bugprone-switch-missing-default-case
|
|
====================================
|
|
|
|
Ensures that switch statements without default cases are flagged, focuses only
|
|
on covering cases with non-enums where the compiler may not issue warnings.
|
|
|
|
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 handling the value.
|
|
|
|
This check helps identify switch statements that are missing a default case,
|
|
allowing developers to ensure that all possible cases are handled properly.
|
|
Adding a default case allows for graceful handling of unexpected or unmatched
|
|
values, reducing the risk of program errors and unexpected behavior.
|
|
|
|
Example:
|
|
|
|
.. code-block:: c++
|
|
|
|
// Example 1:
|
|
// warning: switching on non-enum value without default case may not cover all cases
|
|
switch (i) {
|
|
case 0:
|
|
break;
|
|
}
|
|
|
|
// Example 2:
|
|
enum E { eE1 };
|
|
E e = eE1;
|
|
switch (e) { // no-warning
|
|
case eE1:
|
|
break;
|
|
}
|
|
|
|
// Example 3:
|
|
int i = 0;
|
|
switch (i) { // no-warning
|
|
case 0:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
.. note::
|
|
Enum types are already covered by compiler warnings (comes under -Wswitch)
|
|
when a switch statement does not handle all enum values. This check focuses
|
|
on non-enum types where the compiler warnings may not be present.
|
|
|
|
.. seealso::
|
|
The `CppCoreGuideline ES.79 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#res-default>`_
|
|
provide guidelines on switch statements, including the recommendation to
|
|
always provide a default case.
|