21 unless(hasParent(binaryOperator(unless(isAssignmentOperator()),
22 unless(isComparisonOperator())))),
23 unless(isAssignmentOperator()), unless(isComparisonOperator()),
24 unless(hasAnyOperatorName(
"&&",
"||")),
25 hasDescendant(binaryOperator()))
53 const LangOptions &LangOpts) {
54 if (
const auto *Paren = dyn_cast<ParenExpr>(E)) {
55 addParentheses(Paren->getSubExpr()->IgnoreImpCasts(),
nullptr, Check, SM,
60 const auto *BinOp = dyn_cast<BinaryOperator>(E);
67 if (ParentBinOp !=
nullptr && Precedence1 != Precedence2 && Precedence1 > 0 &&
69 const SourceLocation StartLoc = BinOp->getBeginLoc();
70 const SourceLocation EndLoc =
71 Lexer::getLocForEndOfToken(BinOp->getEndLoc(), 0, SM, LangOpts);
75 "'%0' has higher precedence than '%1'; add parentheses to "
76 "explicitly specify the order of operations")
77 << (Precedence1 > Precedence2 ? BinOp->getOpcodeStr()
78 : ParentBinOp->getOpcodeStr())
79 << (Precedence1 > Precedence2 ? ParentBinOp->getOpcodeStr()
80 : BinOp->getOpcodeStr())
81 << SourceRange(StartLoc, EndLoc);
83 if (EndLoc.isValid()) {
84 Diag << FixItHint::CreateInsertion(StartLoc,
"(")
85 << FixItHint::CreateInsertion(EndLoc,
")");
89 addParentheses(BinOp->getLHS()->IgnoreImpCasts(), BinOp, Check, SM, LangOpts);
90 addParentheses(BinOp->getRHS()->IgnoreImpCasts(), BinOp, Check, SM, LangOpts);