1 .. title:: clang-tidy - bugprone-suspicious-enum-usage
3 bugprone-suspicious-enum-usage
4 ==============================
6 The checker detects various cases when an enum is probably misused (as a bitmask
9 1. When "ADD" or "bitwise OR" is used between two enum which come from different
10 types and these types value ranges are not disjoint.
12 The following cases will be investigated only using :option:`StrictMode`. We
13 regard the enum as a (suspicious)
14 bitmask if the three conditions below are true at the same time:
16 * at most half of the elements of the enum are non pow-of-2 numbers (because of
18 * there is another non pow-of-2 number than the enum constant representing all
19 choices (the result "bitwise OR" operation of all enum elements)
20 * enum type variable/enumconstant is used as an argument of a `+` or "bitwise OR
23 So whenever the non pow-of-2 element is used as a bitmask element we diagnose a
24 misuse and give a warning.
26 2. Investigating the right hand side of `+=` and `|=` operator.
27 3. Check only the enum value side of a `|` and `+` operator if one of them is not
29 4. Check both side of `|` or `+` operator where the enum values are from the
38 enum { G = 10, H = 11, I = 12 };
43 H; // OK, disjoint value intervals in the enum types ->probably good use.
44 flag = B | F; // Warning, have common values so they are probably misused.
54 G = 31 // OK, real bitmask.
64 GG // Problem, forgot to initialize.
70 EE; // Warning at the decl, and note that it was used here as a bitmask.
74 .. option:: StrictMode
77 When non-null the suspicious bitmask usage will be investigated additionally
78 to the different enum usage check.