21 unless(hasParent(binaryOperator(unless(isAssignmentOperator()),
22 unless(isComparisonOperator())))),
23 unless(isAssignmentOperator()), unless(isComparisonOperator()),
24 unless(hasAnyOperatorName(
"&&",
"||")),
25 hasDescendant(binaryOperator()))
52 const BinaryOperator *ParentBinOp,
54 const clang::SourceManager &SM,
55 const clang::LangOptions &LangOpts) {
62 if (ParentBinOp !=
nullptr && Precedence1 != Precedence2 && Precedence1 > 0 &&
64 const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
65 const clang::SourceLocation EndLoc =
66 clang::Lexer::getLocForEndOfToken(BinOp->getEndLoc(), 0, SM, LangOpts);
70 "'%0' has higher precedence than '%1'; add parentheses to "
71 "explicitly specify the order of operations")
72 << (Precedence1 > Precedence2 ? BinOp->getOpcodeStr()
73 : ParentBinOp->getOpcodeStr())
74 << (Precedence1 > Precedence2 ? ParentBinOp->getOpcodeStr()
75 : BinOp->getOpcodeStr())
76 << SourceRange(StartLoc, EndLoc);
78 if (EndLoc.isValid()) {
79 Diag << FixItHint::CreateInsertion(StartLoc,
"(")
80 << FixItHint::CreateInsertion(EndLoc,
")");
84 addParentheses(dyn_cast<BinaryOperator>(BinOp->getLHS()->IgnoreImpCasts()),
85 BinOp, Check, SM, LangOpts);
86 addParentheses(dyn_cast<BinaryOperator>(BinOp->getRHS()->IgnoreImpCasts()),
87 BinOp, Check, SM, LangOpts);