1 .. title:: clang-tidy - bugprone-non-zero-enum-to-bool-conversion
3 bugprone-non-zero-enum-to-bool-conversion
4 =========================================
6 Detect implicit and explicit casts of ``enum`` type into ``bool`` where ``enum``
7 type doesn't have a zero-value enumerator. If the ``enum`` is used only to hold
8 values equal to its enumerators, then conversion to ``bool`` will always result
9 in ``true`` value. This can lead to unnecessary code that reduces readability
10 and maintainability and can result in bugs.
12 May produce false positives if the ``enum`` is used to store other values
13 (used as a bit-mask or zero-initialized on purpose). To deal with them,
14 ``// NOLINT`` or casting first to the underlying type before casting to ``bool``
17 It is important to note that this check will not generate warnings if the
18 definition of the enumeration type is not available.
19 Additionally, C++11 enumeration classes are supported by this check.
21 Overall, this check serves to improve code quality and readability by identifying
22 and flagging instances where implicit or explicit casts from enumeration types to
23 boolean could cause potential issues.
36 void process(EStatus status) {
38 // this true-branch won't be executed
41 // proceed with "valid data"
47 .. option:: EnumIgnoreList
49 Option is used to ignore certain enum types when checking for
50 implicit/explicit casts to bool. It accepts a semicolon-separated list of
51 (fully qualified) enum type names or regular expressions that match the enum
53 The default value is an empty string, which means no enums will be ignored.