NoQ added a comment. In D66847#1648209 <https://reviews.llvm.org/D66847#1648209>, @Szelethus wrote:
> if (isa<FunctionDecl>(D)) { > const auto *FD = dyn_cast<FunctionDecl>(D); // warn: D is known to be a > FunctionDecl, prefer using cast<> > // ... > } > In D66847#1648339 <https://reviews.llvm.org/D66847#1648339>, @Szelethus wrote: > if (A) { > const auto *B = dyn_cast_or_null<FunctionDecl>(A); // warn: A is known to > be non-null, prefer dyn_cast > } > Both of these are must-problems. They are hard to solve via symbolic execution because all execution paths need to be taken into account simultaneously. Eg.: if (isa<FunctionDecl>(D)) { if (coin) D = getDecl(); // Maybe not a FunctionDecl. // It's not enough to know that D is a FunctionDecl assuming coin is false. const auto *FD = dyn_cast<FunctionDecl>(D); // no-warning: } We could maybe make a syntactic checker or a data flow checker to find these anti-patterns. @Charusso also had an idea for a clang-tidy checker that emits fixits for code like `dyn_cast<T>(x)->foo()` ("use 'cast' instead"). CHANGES SINCE LAST ACTION https://reviews.llvm.org/D66847/new/ https://reviews.llvm.org/D66847 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits