Adds new check to clang-tidy.
Check finds conversions from integer literal to bool.
Differential D18745
[clang-tidy] Adds modernize-use-bool-literals check. staronj on Apr 3 2016, 9:26 AM. Authored by
Details
Diff Detail Event TimelineComment Actions Add note in docs/Releasenotes.rst. Besides that it looks good to me, but you still needs the acceptance of Alex (alexfh), who is clang-tidy code owner, Comment Actions Isn't readability-implicit-bool-cast¶ should catch such issues? If not, I think will be good idea to improve that check instead of introducing new one. Comment Actions
Comment Actions I wouldn't add this functionality there. I see that readability-implicit-bool-cast aims much different problem. Comment Actions
Comment Actions So the testing on llvm shows mostly one case - using DEBUG macro like this: /home/prazek/llvm/lib/Support/APInt.cpp:1656:9: warning: implicitly converting integer literal to bool inside macro, use bool literal instead [modernize-use-bool-literals] DEBUG(dbgs() << " " << r[i]); ^ /home/prazek/llvm/include/llvm/Support/Debug.h:92:18: note: expanded from macro 'DEBUG' ^ /home/prazek/llvm/include/llvm/Support/Debug.h:69:48: note: expanded from macro 'DEBUG_WITH_TYPE' ^ Some programers maybe would like to supress this in the case of expressions like while(1), or specially when it is inside macro.
Comment Actions We have a lot of casts related checks, so may be will be good idea to introduce dedicated group for such them? Comment Actions You could also think whether char literals should be converted to true/false, too. Apart from this (and other people's doubts), everything's fine. Comment Actions
Comment Actions Check now finds implicit and explicit conversions from integer literal to bool. Added tests with templates and macros.
|
What about the ones explicitly cast to bool? Do we want to warn on them?