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