compilerplugins/clang/compat.hxx | 8 ++++++++ compilerplugins/clang/unnecessaryparen.cxx | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
New commits: commit 673297dea98892abca3e4421a2e40d8940d7220b Author: Stephan Bergmann <[email protected]> AuthorDate: Wed Apr 7 16:37:50 2021 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Thu Apr 8 07:31:47 2021 +0200 Adapt loplugin:unnecessaryparen to CXXRewrittenBinaryOperator ...as debuted in Clang with <https://github.com/llvm/llvm-project/commit/778dc0f1d49230f53401ae0c190fe460bda4ffd1> "[c++20] Add CXXRewrittenBinaryOperator to represent a comparison operator that is rewritten as a call to multiple other operators" towards Clang 10, and would have caused a false > xmloff/source/style/XMLRtlGutterPropertyHandler.cxx:40:16: error: parentheses immediately inside assignment [loplugin:unnecessaryparen] > rValue <<= (it != aRtlModes.end()); > ^~~~~~~~~~~~~~~~~~~~~~~ with --with-latest-c++ and an appropriate libstdc++. Change-Id: Iede63144dff1e1c833a1da7090b599e792351926 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113744 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> 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)) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
