// we need to not complain about things like TEMP_FAILURE_RETRY(foo(x == 1)),
// so we just match the assignment of `y = (x)` and inspect `x` from there.
Finder->addMatcher(
- binaryOperator(
- hasOperatorName("="),
- hasRHS(ignoringParenCasts(
- binaryOperator(matchers::isComparisonOperator()).bind("binop"))),
- isRHSATempFailureRetryArg()),
+ binaryOperator(hasOperatorName("="),
+ hasRHS(ignoringParenCasts(
+ binaryOperator(isComparisonOperator()).bind("binop"))),
+ isRHSATempFailureRetryArg()),
this);
}
Finder->addMatcher(callExpr(hasAnyArgument(Cast)), this);
Finder->addMatcher(binaryOperator(hasOperatorName("="), hasRHS(Cast)), this);
Finder->addMatcher(
- binaryOperator(matchers::isComparisonOperator(), hasEitherOperand(Cast)),
- this);
+ binaryOperator(isComparisonOperator(), hasEitherOperand(Cast)), this);
}
static unsigned getMaxCalculationWidth(const ASTContext &Context,
void SuspiciousStringCompareCheck::registerMatchers(MatchFinder *Finder) {
// Match relational operators.
const auto ComparisonUnaryOperator = unaryOperator(hasOperatorName("!"));
- const auto ComparisonBinaryOperator =
- binaryOperator(matchers::isComparisonOperator());
+ const auto ComparisonBinaryOperator = binaryOperator(isComparisonOperator());
const auto ComparisonOperator =
expr(anyOf(ComparisonUnaryOperator, ComparisonBinaryOperator));
// Detect suspicious operator with string compare function as operand.
Finder->addMatcher(
- binaryOperator(
- unless(anyOf(matchers::isComparisonOperator(), hasOperatorName("&&"),
- hasOperatorName("||"), hasOperatorName("="))),
- hasEitherOperand(StringCompareCallExpr))
+ binaryOperator(unless(anyOf(isComparisonOperator(), hasOperatorName("&&"),
+ hasOperatorName("||"), hasOperatorName("="))),
+ hasEitherOperand(StringCompareCallExpr))
.bind("suspicious-operator"),
this);
has(ignoringParenImpCasts(integerLiteral(unless(equals(0)))))),
characterLiteral(), cxxBoolLiteral()));
- Finder->addMatcher(binaryOperator(matchers::isComparisonOperator(),
+ Finder->addMatcher(binaryOperator(isComparisonOperator(),
hasEitherOperand(StringCompareCallExpr),
hasEitherOperand(InvalidLiteral))
.bind("invalid-comparison"),
// Matching assignment to owners, with the rhs not being an owner nor creating
// one.
- Finder->addMatcher(binaryOperator(matchers::isAssignmentOperator(),
- hasLHS(IsOwnerType),
+ Finder->addMatcher(binaryOperator(isAssignmentOperator(), hasLHS(IsOwnerType),
hasRHS(unless(ConsideredOwner)))
.bind("owner_assignment"),
this);
// Matching on assignment operations where the RHS is a newly created owner,
// but the LHS is not an owner.
- Finder->addMatcher(binaryOperator(matchers::isAssignmentOperator(),
+ Finder->addMatcher(binaryOperator(isAssignmentOperator(),
hasLHS(unless(IsOwnerType)),
hasRHS(CreatesOwner))
.bind("bad_owner_creation_assignment"),
binaryOperator(anyOf(hasOperatorName("-"), hasOperatorName("/"),
hasOperatorName("%"), hasOperatorName("|"),
hasOperatorName("&"), hasOperatorName("^"),
- matchers::isComparisonOperator(),
- hasOperatorName("&&"), hasOperatorName("||"),
- hasOperatorName("=")),
+ isComparisonOperator(), hasOperatorName("&&"),
+ hasOperatorName("||"), hasOperatorName("=")),
operandsAreEquivalent(),
// Filter noisy false positives.
unless(isInTemplateInstantiation()),
const auto WrongUse = anyOf(
hasParent(binaryOperator(
- matchers::isComparisonOperator(),
+ isComparisonOperator(),
hasEitherOperand(ignoringImpCasts(anyOf(
integerLiteral(equals(1)), integerLiteral(equals(0))))))
.bind("SizeBinaryOp")),
namespace tidy {
namespace matchers {
-AST_MATCHER(BinaryOperator, isAssignmentOperator) {
- return Node.isAssignmentOp();
-}
-
AST_MATCHER(BinaryOperator, isRelationalOperator) {
return Node.isRelationalOp();
}
AST_MATCHER(BinaryOperator, isEqualityOperator) { return Node.isEqualityOp(); }
-AST_MATCHER(BinaryOperator, isComparisonOperator) {
- return Node.isComparisonOp();
-}
-
AST_MATCHER(QualType, isExpensiveToCopy) {
llvm::Optional<bool> IsExpensive =
utils::type_traits::isExpensiveToCopy(Node, Finder->getASTContext());