Detect implicit and explicit conversions of enum to bool,
when enum doesn't have a enumerator with value equal to 0.
In theory such conversion should always return TRUE.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/clang-tidy/bugprone/EnumToBoolConversionCheck.h | ||
---|---|---|
28 | Should language be checked for C++? | |
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst | ||
6 | Please synchronize first statement with statement in Release Notes. Please use double back-ticks for language constructs. | |
49 | Please use single back-ticks for option values. Default value is usually placed after option description. |
Ping, Rebase, Changed Option from Regexp to List, Improved documentation, Removed usage of deprecated API
Such a great check, thanks! I have very minor comments, the most debatable one about the name of the check (but no strong opinion).
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp | ||
---|---|---|
107 | I think the name is a bit generic, do we foresee risk of conflict with other similar checks in the future? I wonder if we should narrow it down to something like bugprone-non-zero-enum-to-bool-conversion. WDYT? | |
clang-tools-extra/clang-tidy/bugprone/EnumToBoolConversionCheck.cpp | ||
24 | Use explicit type | |
25 | The convention in the LLVM repo is to use traditional operators, please keep consistency. | |
28 | Use explicit type | |
73 | Unnecessary empty line | |
clang-tools-extra/docs/ReleaseNotes.rst | ||
108 | Keep alphabetical order. | |
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst | ||
13–14 | I can't think of a case where this could happen, might be worth adding an example below. | |
15 | Nit: Add space between // and NOLINT | |
39 | Nit: use 2 chars indentation | |
40 | Use traditional operators for consistency. | |
42 | won't | |
42 | Remove? | |
clang-tools-extra/test/clang-tidy/checkers/bugprone/enum-to-bool-conversion-cpp11.cpp | ||
10 | Indent with 2 chars instead of 4. | |
17 | Nit: Add 2 chars indentation to align with the code. | |
21 | Maybe test also "int", since it's the most common default? Also test one enum class without explicit underlying type. |
Thank you for review, I will correct comments in this week.
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp | ||
---|---|---|
107 | I'm fine with name change.... | |
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst | ||
42 | enums are ints, you can assign them any value by using static casts or when reading data from external message, so thats why in theory, but in this example you right, there is no "in theory" |
clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-bool-conversion.rst | ||
---|---|---|
13–14 | I thinkg that in STL we got some enums (flags) used as bitmasks... Just wanted to mention that there could be some known false-positives. |
LGTM, thanks! Would be good to fix the last nit before landing.
clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.h | ||
---|---|---|
17 ↗ | (On Diff #511904) | Nit remove excessive whitespace |
I think the name is a bit generic, do we foresee risk of conflict with other similar checks in the future? I wonder if we should narrow it down to something like bugprone-non-zero-enum-to-bool-conversion. WDYT?