diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-04-07 16:37:50 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-04-08 07:31:47 +0200 |
commit | 673297dea98892abca3e4421a2e40d8940d7220b (patch) | |
tree | 04ab85be31704641325bcfb6ff80a0b0ef7c7bad /compilerplugins | |
parent | f458b30b15526e95a6d25820450241fd6234171c (diff) |
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 <sbergman@redhat.com>
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)) |