[NFC] use hasAnyOperatorName and hasAnyOverloadedOperatorName functions in clang-tidy matchers

This commit is contained in:
Nathan James 2020-03-10 00:42:21 +00:00
parent a7a3751775
commit 97572fa6e9
24 changed files with 79 additions and 129 deletions

View File

@ -50,7 +50,7 @@ void StringFindStartswithCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher( Finder->addMatcher(
// Match [=!]= with a zero on one side and a string.find on the other. // Match [=!]= with a zero on one side and a string.find on the other.
binaryOperator( binaryOperator(
anyOf(hasOperatorName("=="), hasOperatorName("!=")), hasAnyOperatorName("==", "!="),
hasEitherOperand(ignoringParenImpCasts(ZeroLiteral)), hasEitherOperand(ignoringParenImpCasts(ZeroLiteral)),
hasEitherOperand(ignoringParenImpCasts(StringFind.bind("findexpr")))) hasEitherOperand(ignoringParenImpCasts(StringFind.bind("findexpr"))))
.bind("expr"), .bind("expr"),

View File

@ -19,15 +19,11 @@ namespace bugprone {
void IntegerDivisionCheck::registerMatchers(MatchFinder *Finder) { void IntegerDivisionCheck::registerMatchers(MatchFinder *Finder) {
const auto IntType = hasType(isInteger()); const auto IntType = hasType(isInteger());
const auto BinaryOperators = binaryOperator(anyOf( const auto BinaryOperators = binaryOperator(
hasOperatorName("%"), hasOperatorName("<<"), hasOperatorName(">>"), hasAnyOperatorName("%", "<<", ">>", "<<", "^", "|", "&", "||", "&&", "<",
hasOperatorName("<<"), hasOperatorName("^"), hasOperatorName("|"), ">", "<=", ">=", "==", "!="));
hasOperatorName("&"), hasOperatorName("||"), hasOperatorName("&&"),
hasOperatorName("<"), hasOperatorName(">"), hasOperatorName("<="),
hasOperatorName(">="), hasOperatorName("=="), hasOperatorName("!=")));
const auto UnaryOperators = const auto UnaryOperators = unaryOperator(hasAnyOperatorName("~", "!"));
unaryOperator(anyOf(hasOperatorName("~"), hasOperatorName("!")));
const auto Exceptions = const auto Exceptions =
anyOf(BinaryOperators, conditionalOperator(), binaryConditionalOperator(), anyOf(BinaryOperators, conditionalOperator(), binaryConditionalOperator(),

View File

@ -28,8 +28,7 @@ void MisplacedPointerArithmeticInAllocCheck::registerMatchers(
hasInitializer(ignoringParenImpCasts( hasInitializer(ignoringParenImpCasts(
declRefExpr(hasDeclaration(AllocFunc))))); declRefExpr(hasDeclaration(AllocFunc)))));
const auto AdditiveOperator = const auto AdditiveOperator = binaryOperator(hasAnyOperatorName("+", "-"));
binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-")));
const auto IntExpr = expr(hasType(isInteger())); const auto IntExpr = expr(hasType(isInteger()));

View File

@ -29,9 +29,7 @@ void MisplacedWideningCastCheck::storeOptions(
void MisplacedWideningCastCheck::registerMatchers(MatchFinder *Finder) { void MisplacedWideningCastCheck::registerMatchers(MatchFinder *Finder) {
const auto Calc = const auto Calc =
expr(anyOf(binaryOperator( expr(anyOf(binaryOperator(hasAnyOperatorName("+", "-", "*", "<<")),
anyOf(hasOperatorName("+"), hasOperatorName("-"),
hasOperatorName("*"), hasOperatorName("<<"))),
unaryOperator(hasOperatorName("~"))), unaryOperator(hasOperatorName("~"))),
hasType(isInteger())) hasType(isInteger()))
.bind("Calc"); .bind("Calc");

View File

@ -48,8 +48,7 @@ void PosixReturnCheck::registerMatchers(MatchFinder *Finder) {
this); this);
Finder->addMatcher( Finder->addMatcher(
binaryOperator( binaryOperator(
anyOf(hasOperatorName("=="), hasOperatorName("!="), hasAnyOperatorName("==", "!=", "<=", "<"),
hasOperatorName("<="), hasOperatorName("<")),
hasLHS(callExpr(callee(functionDecl( hasLHS(callExpr(callee(functionDecl(
anyOf(matchesName("^::posix_"), matchesName("^::pthread_")), anyOf(matchesName("^::posix_"), matchesName("^::pthread_")),
unless(hasName("::posix_openpt")))))), unless(hasName("::posix_openpt")))))),

View File

@ -28,7 +28,7 @@ void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) {
.bind("sizeof"), .bind("sizeof"),
// Ignore ARRAYSIZE(<array of containers>) pattern. // Ignore ARRAYSIZE(<array of containers>) pattern.
unless(hasAncestor(binaryOperator( unless(hasAncestor(binaryOperator(
anyOf(hasOperatorName("/"), hasOperatorName("%")), hasAnyOperatorName("/", "%"),
hasLHS(ignoringParenCasts(sizeOfExpr(expr()))), hasLHS(ignoringParenCasts(sizeOfExpr(expr()))),
hasRHS(ignoringParenCasts(equalsBoundNode("sizeof"))))))), hasRHS(ignoringParenCasts(equalsBoundNode("sizeof"))))))),
this); this);

View File

@ -231,10 +231,7 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher( Finder->addMatcher(
binaryOperator( binaryOperator(
anyOf(hasOperatorName("=="), hasOperatorName("!="), hasAnyOperatorName("==", "!=", "<", "<=", ">", ">=", "+", "-"),
hasOperatorName("<"), hasOperatorName("<="),
hasOperatorName(">"), hasOperatorName(">="),
hasOperatorName("+"), hasOperatorName("-")),
hasEitherOperand(expr(anyOf( hasEitherOperand(expr(anyOf(
ignoringParenImpCasts(SizeOfExpr), ignoringParenImpCasts(SizeOfExpr),
ignoringParenImpCasts(binaryOperator( ignoringParenImpCasts(binaryOperator(

View File

@ -20,8 +20,7 @@ namespace bugprone {
void StringIntegerAssignmentCheck::registerMatchers(MatchFinder *Finder) { void StringIntegerAssignmentCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher( Finder->addMatcher(
cxxOperatorCallExpr( cxxOperatorCallExpr(
anyOf(hasOverloadedOperatorName("="), hasAnyOverloadedOperatorName("=", "+="),
hasOverloadedOperatorName("+=")),
callee(cxxMethodDecl(ofClass(classTemplateSpecializationDecl( callee(cxxMethodDecl(ofClass(classTemplateSpecializationDecl(
hasName("::std::basic_string"), hasName("::std::basic_string"),
hasTemplateArgument(0, refersToType(hasCanonicalType( hasTemplateArgument(0, refersToType(hasCanonicalType(

View File

@ -131,7 +131,7 @@ void SuspiciousEnumUsageCheck::registerMatchers(MatchFinder *Finder) {
this); this);
Finder->addMatcher( Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("|")), binaryOperator(hasAnyOperatorName("+", "|"),
hasLHS(enumExpr("lhsExpr", "enumDecl")), hasLHS(enumExpr("lhsExpr", "enumDecl")),
hasRHS(expr(enumExpr("rhsExpr", ""), hasRHS(expr(enumExpr("rhsExpr", ""),
ignoringImpCasts(hasType( ignoringImpCasts(hasType(
@ -139,16 +139,15 @@ void SuspiciousEnumUsageCheck::registerMatchers(MatchFinder *Finder) {
this); this);
Finder->addMatcher( Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("|")), binaryOperator(hasAnyOperatorName("+", "|"),
hasEitherOperand( hasEitherOperand(
expr(hasType(isInteger()), unless(enumExpr("", "")))), expr(hasType(isInteger()), unless(enumExpr("", "")))),
hasEitherOperand(enumExpr("enumExpr", "enumDecl"))), hasEitherOperand(enumExpr("enumExpr", "enumDecl"))),
this); this);
Finder->addMatcher( Finder->addMatcher(binaryOperator(hasAnyOperatorName("|=", "+="),
binaryOperator(anyOf(hasOperatorName("|="), hasOperatorName("+=")), hasRHS(enumExpr("enumExpr", "enumDecl"))),
hasRHS(enumExpr("enumExpr", "enumDecl"))), this);
this);
} }
void SuspiciousEnumUsageCheck::checkSuspiciousBitmaskUsage( void SuspiciousEnumUsageCheck::checkSuspiciousBitmaskUsage(

View File

@ -116,9 +116,8 @@ void SuspiciousStringCompareCheck::registerMatchers(MatchFinder *Finder) {
whileStmt(hasCondition(StringCompareCallExpr)), whileStmt(hasCondition(StringCompareCallExpr)),
doStmt(hasCondition(StringCompareCallExpr)), doStmt(hasCondition(StringCompareCallExpr)),
forStmt(hasCondition(StringCompareCallExpr)), forStmt(hasCondition(StringCompareCallExpr)),
binaryOperator( binaryOperator(hasAnyOperatorName("&&", "||"),
anyOf(hasOperatorName("&&"), hasOperatorName("||")), hasEitherOperand(StringCompareCallExpr))))
hasEitherOperand(StringCompareCallExpr))))
.bind("missing-comparison"), .bind("missing-comparison"),
this); this);
} }

View File

@ -40,9 +40,9 @@ void UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
// Self-check: Code compares something with 'this' pointer. We don't check // Self-check: Code compares something with 'this' pointer. We don't check
// whether it is actually the parameter what we compare. // whether it is actually the parameter what we compare.
const auto HasNoSelfCheck = cxxMethodDecl(unless(hasDescendant( const auto HasNoSelfCheck = cxxMethodDecl(unless(
binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")), hasDescendant(binaryOperator(hasAnyOperatorName("==", "!="),
has(ignoringParenCasts(cxxThisExpr())))))); has(ignoringParenCasts(cxxThisExpr()))))));
// Both copy-and-swap and copy-and-move method creates a copy first and // Both copy-and-swap and copy-and-move method creates a copy first and
// assign it to 'this' with swap or move. // assign it to 'this' with swap or move.

View File

@ -276,13 +276,11 @@ void UseAfterMoveFinder::getDeclRefs(
.bind("declref"); .bind("declref");
addDeclRefs(match(findAll(DeclRefMatcher), *S->getStmt(), *Context)); addDeclRefs(match(findAll(DeclRefMatcher), *S->getStmt(), *Context));
addDeclRefs(match( addDeclRefs(match(findAll(cxxOperatorCallExpr(
findAll(cxxOperatorCallExpr(anyOf(hasOverloadedOperatorName("*"), hasAnyOverloadedOperatorName("*", "->", "[]"),
hasOverloadedOperatorName("->"), hasArgument(0, DeclRefMatcher))
hasOverloadedOperatorName("[]")), .bind("operator")),
hasArgument(0, DeclRefMatcher)) *S->getStmt(), *Context));
.bind("operator")),
*S->getStmt(), *Context));
} }
} }

View File

@ -18,8 +18,7 @@ namespace tidy {
namespace cert { namespace cert {
void PostfixOperatorCheck::registerMatchers(MatchFinder *Finder) { void PostfixOperatorCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(functionDecl(anyOf(hasOverloadedOperatorName("++"), Finder->addMatcher(functionDecl(hasAnyOverloadedOperatorName("++", "--"),
hasOverloadedOperatorName("--")),
unless(isInstantiated())) unless(isInstantiated()))
.bind("decl"), .bind("decl"),
this); this);

View File

@ -27,16 +27,13 @@ void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) {
// Flag all operators +, -, +=, -=, ++, -- that result in a pointer // Flag all operators +, -, +=, -=, ++, -- that result in a pointer
Finder->addMatcher( Finder->addMatcher(
binaryOperator( binaryOperator(
anyOf(hasOperatorName("+"), hasOperatorName("-"), hasAnyOperatorName("+", "-", "+=", "-="), AllPointerTypes,
hasOperatorName("+="), hasOperatorName("-=")),
AllPointerTypes,
unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit())))))) unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
.bind("expr"), .bind("expr"),
this); this);
Finder->addMatcher( Finder->addMatcher(
unaryOperator(anyOf(hasOperatorName("++"), hasOperatorName("--")), unaryOperator(hasAnyOperatorName("++", "--"), hasType(pointerType()))
hasType(pointerType()))
.bind("expr"), .bind("expr"),
this); this);

View File

@ -48,9 +48,7 @@ void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
// Match binary bitwise operations on signed integer arguments. // Match binary bitwise operations on signed integer arguments.
Finder->addMatcher( Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("^"), hasOperatorName("|"), binaryOperator(hasAnyOperatorName("^", "|", "&", "^=", "|=", "&="),
hasOperatorName("&"), hasOperatorName("^="),
hasOperatorName("|="), hasOperatorName("&=")),
unless(allOf(hasLHS(IsStdBitmask), hasRHS(IsStdBitmask))), unless(allOf(hasLHS(IsStdBitmask), hasRHS(IsStdBitmask))),
@ -62,8 +60,7 @@ void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
// Shifting and complement is not allowed for any signed integer type because // Shifting and complement is not allowed for any signed integer type because
// the sign bit may corrupt the result. // the sign bit may corrupt the result.
Finder->addMatcher( Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("<<"), hasOperatorName(">>"), binaryOperator(hasAnyOperatorName("<<", ">>", "<<=", ">>="),
hasOperatorName("<<="), hasOperatorName(">>=")),
hasEitherOperand(SignedIntegerOperand), hasEitherOperand(SignedIntegerOperand),
hasLHS(hasType(isInteger())), hasRHS(hasType(isInteger()))) hasLHS(hasType(isInteger())), hasRHS(hasType(isInteger())))
.bind("binary-sign-interference"), .bind("binary-sign-interference"),

View File

@ -532,14 +532,12 @@ static bool retrieveSymbolicExpr(const MatchFinder::MatchResult &Result,
static ast_matchers::internal::Matcher<Expr> static ast_matchers::internal::Matcher<Expr>
matchBinOpIntegerConstantExpr(StringRef Id) { matchBinOpIntegerConstantExpr(StringRef Id) {
const auto BinOpCstExpr = const auto BinOpCstExpr =
expr( expr(anyOf(binaryOperator(hasAnyOperatorName("+", "|", "&"),
anyOf(binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("|"), hasEitherOperand(matchSymbolicExpr(Id)),
hasOperatorName("&")), hasEitherOperand(matchIntegerConstantExpr(Id))),
hasEitherOperand(matchSymbolicExpr(Id)), binaryOperator(hasOperatorName("-"),
hasEitherOperand(matchIntegerConstantExpr(Id))), hasLHS(matchSymbolicExpr(Id)),
binaryOperator(hasOperatorName("-"), hasRHS(matchIntegerConstantExpr(Id)))))
hasLHS(matchSymbolicExpr(Id)),
hasRHS(matchIntegerConstantExpr(Id)))))
.bind(Id); .bind(Id);
return ignoringParenImpCasts(BinOpCstExpr); return ignoringParenImpCasts(BinOpCstExpr);
} }
@ -594,10 +592,7 @@ matchRelationalIntegerConstantExpr(StringRef Id) {
const auto OverloadedOperatorExpr = const auto OverloadedOperatorExpr =
cxxOperatorCallExpr( cxxOperatorCallExpr(
anyOf(hasOverloadedOperatorName("=="), hasAnyOverloadedOperatorName("==", "!=", "<", "<=", ">", ">="),
hasOverloadedOperatorName("!="), hasOverloadedOperatorName("<"),
hasOverloadedOperatorName("<="), hasOverloadedOperatorName(">"),
hasOverloadedOperatorName(">=")),
// Filter noisy false positives. // Filter noisy false positives.
unless(isMacro()), unless(isInTemplateInstantiation())) unless(isMacro()), unless(isInTemplateInstantiation()))
.bind(OverloadId); .bind(OverloadId);
@ -833,11 +828,9 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
// Binary with equivalent operands, like (X != 2 && X != 2). // Binary with equivalent operands, like (X != 2 && X != 2).
Finder->addMatcher( Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("-"), hasOperatorName("/"), binaryOperator(anyOf(isComparisonOperator(),
hasOperatorName("%"), hasOperatorName("|"), hasAnyOperatorName("-", "/", "%", "|", "&", "^",
hasOperatorName("&"), hasOperatorName("^"), "&&", "||", "=")),
isComparisonOperator(), hasOperatorName("&&"),
hasOperatorName("||"), hasOperatorName("=")),
operandsAreEquivalent(), operandsAreEquivalent(),
// Filter noisy false positives. // Filter noisy false positives.
unless(isInTemplateInstantiation()), unless(isInTemplateInstantiation()),
@ -852,9 +845,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
// Logical or bitwise operator with equivalent nested operands, like (X && Y // Logical or bitwise operator with equivalent nested operands, like (X && Y
// && X) or (X && (Y && X)) // && X) or (X && (Y && X))
Finder->addMatcher( Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("|"), hasOperatorName("&"), binaryOperator(hasAnyOperatorName("|", "&", "||", "&&", "^"),
hasOperatorName("||"), hasOperatorName("&&"),
hasOperatorName("^")),
nestedOperandsAreEquivalent(), nestedOperandsAreEquivalent(),
// Filter noisy false positives. // Filter noisy false positives.
unless(isInTemplateInstantiation()), unless(isInTemplateInstantiation()),
@ -873,30 +864,20 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
this); this);
// Overloaded operators with equivalent operands. // Overloaded operators with equivalent operands.
Finder->addMatcher( Finder->addMatcher(cxxOperatorCallExpr(
cxxOperatorCallExpr( hasAnyOverloadedOperatorName(
anyOf( "-", "/", "%", "|", "&", "^", "==", "!=", "<",
hasOverloadedOperatorName("-"), hasOverloadedOperatorName("/"), "<=", ">", ">=", "&&", "||", "="),
hasOverloadedOperatorName("%"), hasOverloadedOperatorName("|"), parametersAreEquivalent(),
hasOverloadedOperatorName("&"), hasOverloadedOperatorName("^"), // Filter noisy false positives.
hasOverloadedOperatorName("=="), hasOverloadedOperatorName("!="), unless(isMacro()), unless(isInTemplateInstantiation()))
hasOverloadedOperatorName("<"), hasOverloadedOperatorName("<="), .bind("call"),
hasOverloadedOperatorName(">"), hasOverloadedOperatorName(">="), this);
hasOverloadedOperatorName("&&"), hasOverloadedOperatorName("||"),
hasOverloadedOperatorName("=")),
parametersAreEquivalent(),
// Filter noisy false positives.
unless(isMacro()), unless(isInTemplateInstantiation()))
.bind("call"),
this);
// Overloaded operators with equivalent operands. // Overloaded operators with equivalent operands.
Finder->addMatcher( Finder->addMatcher(
cxxOperatorCallExpr( cxxOperatorCallExpr(
anyOf(hasOverloadedOperatorName("|"), hasOverloadedOperatorName("&"), hasAnyOverloadedOperatorName("|", "&", "||", "&&", "^"),
hasOverloadedOperatorName("||"),
hasOverloadedOperatorName("&&"),
hasOverloadedOperatorName("^")),
nestedParametersAreEquivalent(), argumentCountIs(2), nestedParametersAreEquivalent(), argumentCountIs(2),
// Filter noisy false positives. // Filter noisy false positives.
unless(isMacro()), unless(isInTemplateInstantiation())) unless(isMacro()), unless(isInTemplateInstantiation()))
@ -910,9 +891,8 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
has(unaryOperator( has(unaryOperator(
hasOperatorName("!"), hasOperatorName("!"),
hasUnaryOperand(ignoringParenImpCasts(binaryOperator( hasUnaryOperand(ignoringParenImpCasts(binaryOperator(
anyOf(hasOperatorName("|"), hasOperatorName("&")), hasAnyOperatorName("|", "&"),
hasLHS(anyOf(binaryOperator(anyOf(hasOperatorName("|"), hasLHS(anyOf(binaryOperator(hasAnyOperatorName("|", "&")),
hasOperatorName("&"))),
integerLiteral())), integerLiteral())),
hasRHS(integerLiteral()))))) hasRHS(integerLiteral())))))
.bind("logical-bitwise-confusion"))), .bind("logical-bitwise-confusion"))),
@ -971,13 +951,13 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
// Match expressions like: x < 2 && x > 2. // Match expressions like: x < 2 && x > 2.
const auto ComparisonLeft = matchRelationalIntegerConstantExpr("lhs"); const auto ComparisonLeft = matchRelationalIntegerConstantExpr("lhs");
const auto ComparisonRight = matchRelationalIntegerConstantExpr("rhs"); const auto ComparisonRight = matchRelationalIntegerConstantExpr("rhs");
Finder->addMatcher( Finder->addMatcher(binaryOperator(hasAnyOperatorName("||", "&&"),
binaryOperator(anyOf(hasOperatorName("||"), hasOperatorName("&&")), hasLHS(ComparisonLeft),
hasLHS(ComparisonLeft), hasRHS(ComparisonRight), hasRHS(ComparisonRight),
// Already reported as redundant. // Already reported as redundant.
unless(operandsAreEquivalent())) unless(operandsAreEquivalent()))
.bind("comparisons-of-symbol-and-const"), .bind("comparisons-of-symbol-and-const"),
this); this);
} }
void RedundantExpressionCheck::checkArithmeticExpr( void RedundantExpressionCheck::checkArithmeticExpr(

View File

@ -38,7 +38,7 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
.bind("castExpr"))); .bind("castExpr")));
auto AssertExprRoot = anyOf( auto AssertExprRoot = anyOf(
binaryOperator( binaryOperator(
anyOf(hasOperatorName("&&"), hasOperatorName("==")), hasAnyOperatorName("&&", "=="),
hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))), hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))),
anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)), anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
anything())) anything()))

View File

@ -192,10 +192,10 @@ void UseDefaultMemberInitCheck::storeOptions(
void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) { void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
auto Init = auto Init =
anyOf(stringLiteral(), characterLiteral(), integerLiteral(), anyOf(stringLiteral(), characterLiteral(), integerLiteral(),
unaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-")), unaryOperator(hasAnyOperatorName("+", "-"),
hasUnaryOperand(integerLiteral())), hasUnaryOperand(integerLiteral())),
floatLiteral(), floatLiteral(),
unaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-")), unaryOperator(hasAnyOperatorName("+", "-"),
hasUnaryOperand(floatLiteral())), hasUnaryOperand(floatLiteral())),
cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(), cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
initListExpr(), declRefExpr(to(enumConstantDecl()))); initListExpr(), declRefExpr(to(enumConstantDecl())));

View File

@ -85,8 +85,7 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
expr(hasType(ValidContainer)).bind("STLObject")); expr(hasType(ValidContainer)).bind("STLObject"));
Finder->addMatcher( Finder->addMatcher(
cxxOperatorCallExpr( cxxOperatorCallExpr(
anyOf(hasOverloadedOperatorName("=="), hasAnyOverloadedOperatorName("==", "!="),
hasOverloadedOperatorName("!=")),
anyOf(allOf(hasArgument(0, WrongComparend), hasArgument(1, STLArg)), anyOf(allOf(hasArgument(0, WrongComparend), hasArgument(1, STLArg)),
allOf(hasArgument(0, STLArg), hasArgument(1, WrongComparend))), allOf(hasArgument(0, STLArg), hasArgument(1, WrongComparend))),
unless(hasAncestor( unless(hasAncestor(

View File

@ -293,12 +293,11 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
.bind("implicitCastToBool"), .bind("implicitCastToBool"),
this); this);
auto boolComparison = binaryOperator( auto boolComparison = binaryOperator(hasAnyOperatorName("==", "!="),
anyOf(hasOperatorName("=="), hasOperatorName("!=")), hasLHS(implicitCastFromBool),
hasLHS(implicitCastFromBool), hasRHS(implicitCastFromBool)); hasRHS(implicitCastFromBool));
auto boolOpAssignment = auto boolOpAssignment = binaryOperator(hasAnyOperatorName("|=", "&="),
binaryOperator(anyOf(hasOperatorName("|="), hasOperatorName("&=")), hasLHS(expr(hasType(booleanType()))));
hasLHS(expr(hasType(booleanType()))));
auto bitfieldAssignment = binaryOperator( auto bitfieldAssignment = binaryOperator(
hasLHS(memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)))))); hasLHS(memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1))))));
auto bitfieldConstruct = cxxConstructorDecl(hasDescendant(cxxCtorInitializer( auto bitfieldConstruct = cxxConstructorDecl(hasDescendant(cxxCtorInitializer(

View File

@ -28,8 +28,7 @@ void NonConstParameterCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(declRefExpr().bind("Ref"), this); Finder->addMatcher(declRefExpr().bind("Ref"), this);
// Analyse parameter usage in function. // Analyse parameter usage in function.
Finder->addMatcher(stmt(anyOf(unaryOperator(anyOf(hasOperatorName("++"), Finder->addMatcher(stmt(anyOf(unaryOperator(hasAnyOperatorName("++", "--")),
hasOperatorName("--"))),
binaryOperator(), callExpr(), returnStmt(), binaryOperator(), callExpr(), returnStmt(),
cxxConstructExpr())) cxxConstructExpr()))
.bind("Mark"), .bind("Mark"),

View File

@ -81,7 +81,7 @@ void registerMatchersForGetEquals(MatchFinder *Finder,
// Matches against nullptr. // Matches against nullptr.
Finder->addMatcher( Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")), binaryOperator(hasAnyOperatorName("==", "!="),
hasEitherOperand(ignoringImpCasts( hasEitherOperand(ignoringImpCasts(
anyOf(cxxNullPtrLiteralExpr(), gnuNullExpr(), anyOf(cxxNullPtrLiteralExpr(), gnuNullExpr(),
integerLiteral(equals(0))))), integerLiteral(equals(0))))),

View File

@ -150,11 +150,7 @@ void RedundantStringCStrCheck::registerMatchers(
// Detect: 's == str.c_str()' -> 's == str' // Detect: 's == str.c_str()' -> 's == str'
Finder->addMatcher( Finder->addMatcher(
cxxOperatorCallExpr( cxxOperatorCallExpr(
anyOf( hasAnyOverloadedOperatorName("<", ">", ">=", "<=", "!=", "==", "+"),
hasOverloadedOperatorName("<"), hasOverloadedOperatorName(">"),
hasOverloadedOperatorName(">="), hasOverloadedOperatorName("<="),
hasOverloadedOperatorName("!="), hasOverloadedOperatorName("=="),
hasOverloadedOperatorName("+")),
anyOf(allOf(hasArgument(0, StringExpr), anyOf(allOf(hasArgument(0, StringExpr),
hasArgument(1, StringCStrCallExpr)), hasArgument(1, StringCStrCallExpr)),
allOf(hasArgument(0, StringCStrCallExpr), allOf(hasArgument(0, StringCStrCallExpr),
@ -163,11 +159,11 @@ void RedundantStringCStrCheck::registerMatchers(
// Detect: 'dst += str.c_str()' -> 'dst += str' // Detect: 'dst += str.c_str()' -> 'dst += str'
// Detect: 's = str.c_str()' -> 's = str' // Detect: 's = str.c_str()' -> 's = str'
Finder->addMatcher(cxxOperatorCallExpr(anyOf(hasOverloadedOperatorName("="), Finder->addMatcher(
hasOverloadedOperatorName("+=")), cxxOperatorCallExpr(hasAnyOverloadedOperatorName("=", "+="),
hasArgument(0, StringExpr), hasArgument(0, StringExpr),
hasArgument(1, StringCStrCallExpr)), hasArgument(1, StringCStrCallExpr)),
this); this);
// Detect: 'dst.append(str.c_str())' -> 'dst.append(str)' // Detect: 'dst.append(str.c_str())' -> 'dst.append(str)'
Finder->addMatcher( Finder->addMatcher(

View File

@ -38,7 +38,7 @@ void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
// Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0. // Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0.
Finder->addMatcher( Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")), binaryOperator(hasAnyOperatorName("==", "!="),
hasEitherOperand(StrCompare.bind("compare")), hasEitherOperand(StrCompare.bind("compare")),
hasEitherOperand(integerLiteral(equals(0)).bind("zero"))) hasEitherOperand(integerLiteral(equals(0)).bind("zero")))
.bind("match2"), .bind("match2"),