diff options
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/compat.hxx | 8 | ||||
-rw-r--r-- | compilerplugins/clang/unnecessaryparen.cxx | 14 |
2 files changed, 21 insertions, 1 deletions
diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index ae7557b71956..897d9fe855c0 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -321,6 +321,14 @@ inline bool isComparisonOp(clang::CXXOperatorCallExpr const * callExpr) || op == OO_EqualEqual || op == OO_ExclaimEqual; } +inline bool isPtrMemOp(clang::BinaryOperatorKind op) { +#if CLANG_VERSION >= 80000 + return clang::BinaryOperator::isPtrMemOp(op); +#else + return op == clang::BO_PtrMemD || op == clang::BO_PtrMemI; +#endif +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx index e93dfa64b5ec..d39dd074eb43 100644 --- a/compilerplugins/clang/unnecessaryparen.cxx +++ b/compilerplugins/clang/unnecessaryparen.cxx @@ -68,6 +68,11 @@ Expr const * ignoreAllImplicit(Expr const * expr) { return expr; } +bool isParenWorthyOpcode(BinaryOperatorKind op) { + return !(BinaryOperator::isMultiplicativeOp(op) || BinaryOperator::isAdditiveOp(op) + || compat::isPtrMemOp(op)); +} + class UnnecessaryParen: public loplugin::FilteringRewritePlugin<UnnecessaryParen> { @@ -430,9 +435,16 @@ bool UnnecessaryParen::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callE // Sometimes parentheses make the RHS of an assignment easier to read by // visually disambiguating the = from a call to == auto sub = parenExpr->getSubExpr(); +#if CLANG_VERSION >= 100000 + if (auto const e = dyn_cast<CXXRewrittenBinaryOperator>(sub)) { + if (isParenWorthyOpcode(e->getDecomposedForm().Opcode)) { + return true; + } + } +#endif if (auto subBinOp = dyn_cast<BinaryOperator>(sub)) { - if (!(subBinOp->isMultiplicativeOp() || subBinOp->isAdditiveOp() || subBinOp->isPtrMemOp())) + if (isParenWorthyOpcode(subBinOp->getOpcode())) return true; } if (auto subOperatorCall = dyn_cast<CXXOperatorCallExpr>(sub)) |