[PATCH] D59802: [clang-tidy] Add new checker: llvm-avoid-cast-in-conditional
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 26 11:46:00 PDT 2019
aaron.ballman added a comment.
Should this check also try to find this pattern:
if (dyn_cast<Frobble>(Bobble))
...
in order to recommend the proper replacement:
if (isa<Frobble>(Bobble))
...
I ask because the name `llvm-avoid-cast-in-conditional` sounds like it would also cover this situation and I run into it during code reviews with some frequency (more often than I run into `cast<>` being used in a conditional).
================
Comment at: clang-tools-extra/clang-tidy/llvm/AvoidCastInConditionalCheck.cpp:20
+void AvoidCastInConditionalCheck::registerMatchers(MatchFinder *Finder) {
+ Finder->addMatcher(
+ ifStmt(anyOf(
----------------
No need to register this matcher if C++ isn't enabled.
================
Comment at: clang-tools-extra/clang-tidy/llvm/AvoidCastInConditionalCheck.cpp:35-36
+ diag(MatchedDecl->getBeginLoc(),
+ "Found cast<> in conditional statement; consider using dyn_cast<> if "
+ "it can fail, or removal of conditional if it can't.");
+ ;
----------------
clang-tidy diagnostics should not be complete sentences; you should make this ungrammatical. How about: `cast<> in conditional will assert rather than return a null pointer`?
================
Comment at: clang-tools-extra/clang-tidy/llvm/AvoidCastInConditionalCheck.cpp:37
+ "it can fail, or removal of conditional if it can't.");
+ ;
+ }
----------------
Spurious semicolon?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59802/new/
https://reviews.llvm.org/D59802
More information about the cfe-commits
mailing list