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
80 lines
2.1 KiB
ReStructuredText
80 lines
2.1 KiB
ReStructuredText
.. title:: clang-tidy - bugprone-suspicious-enum-usage
|
|
|
|
bugprone-suspicious-enum-usage
|
|
==============================
|
|
|
|
The checker detects various cases when an enum is probably misused
|
|
(as a bitmask).
|
|
|
|
1. When "ADD" or "bitwise OR" is used between two enum which come
|
|
from different types and these types value ranges are not disjoint.
|
|
|
|
The following cases will be investigated only using :option:`StrictMode`. We
|
|
regard the enum as a (suspicious)
|
|
bitmask if the three conditions below are true at the same time:
|
|
|
|
* at most half of the elements of the enum are non pow-of-2 numbers (because of
|
|
short enumerations)
|
|
* there is another non pow-of-2 number than the enum constant representing all
|
|
choices (the result "bitwise OR" operation of all enum elements)
|
|
* enum type variable/enumconstant is used as an argument of a `+` or "bitwise
|
|
OR" operator
|
|
|
|
So whenever the non pow-of-2 element is used as a bitmask element we diagnose a
|
|
misuse and give a warning.
|
|
|
|
2. Investigating the right hand side of ``+=`` and ``|=`` operator.
|
|
3. Check only the enum value side of a ``|`` and ``+`` operator if one of
|
|
them is not enum val.
|
|
4. Check both side of ``|`` or ``+`` operator where the enum values are from
|
|
the same enum type.
|
|
|
|
Examples:
|
|
|
|
.. code-block:: c++
|
|
|
|
enum { A, B, C };
|
|
enum { D, E, F = 5 };
|
|
enum { G = 10, H = 11, I = 12 };
|
|
|
|
unsigned flag;
|
|
flag =
|
|
A |
|
|
H; // OK, disjoint value intervals in the enum types ->probably good use.
|
|
flag = B | F; // Warning, have common values so they are probably misused.
|
|
|
|
// Case 2:
|
|
enum Bitmask {
|
|
A = 0,
|
|
B = 1,
|
|
C = 2,
|
|
D = 4,
|
|
E = 8,
|
|
F = 16,
|
|
G = 31 // OK, real bitmask.
|
|
};
|
|
|
|
enum Almostbitmask {
|
|
AA = 0,
|
|
BB = 1,
|
|
CC = 2,
|
|
DD = 4,
|
|
EE = 8,
|
|
FF = 16,
|
|
GG // Problem, forgot to initialize.
|
|
};
|
|
|
|
unsigned flag = 0;
|
|
flag |= E; // OK.
|
|
flag |=
|
|
EE; // Warning at the decl, and note that it was used here as a bitmask.
|
|
|
|
Options
|
|
-------
|
|
|
|
.. option:: StrictMode
|
|
|
|
Default value: 0.
|
|
When non-null the suspicious bitmask usage will be investigated additionally
|
|
to the different enum usage check.
|