alexfh added inline comments.
================
Comment at: lib/StaticAnalyzer/Checkers/DeadStatusChecker.cpp:33
+
+ const Expr *hasNullptr(const BinaryOperator *BO) const {
+ const Expr *ret = nullptr;
----------------
george.karpenkov wrote:
> Could this be rewritten as a matcher instead? Surely there must be one
> comparing the literal to null?
For this particular part a matchers-based solution might be a bit wordy:
binaryOperator(anyOf(
allOf(hasLHS(ignoringParenCasts(nullPointerConstant())),
hasRHS(expr().bind("other"))),
allOf(hasRHS(ignoringParenCasts(nullPointerConstant())),
hasLHS(expr().bind("other")))))
But maybe it's time to add a helper matcher similar to hasEitherOperand, for
example:
inline internal::Matcher<BinaryOperator> hasOperands(
const internal::Matcher<Expr> &One, const internal::Matcher<Expr>
&Another) {
return anyOf(allOf(hasLHS(One), hasRHS(Another)), allOf(hasRHS(One),
hasLHS(Another)));
}
This can be done locally, but I wouldn't object adding it to ASTMatchers.h,
since it could already be used a few times in the existing code (at least in
clang-tidy/bugprone/IncorrectRoundingsCheck.cpp and
clang-tidy/misc/RedundantExpressionCheck.cpp).
Repository:
rC Clang
https://reviews.llvm.org/D47554
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits