summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-04-11 16:55:25 +0200
committerStephan Bergmann <sbergman@redhat.com>2020-04-11 17:44:54 +0200
commit88629b55041b9e7ff5c94afeb2aae725a5898687 (patch)
treee4baccda723eebe022dacb0515f9fea36a48a9ee /compilerplugins
parentdd1746d608e091e1f3d06a588f689d7047cc6748 (diff)
Adapt loplugin:unnecessaryparen to C++20 CXXRewrittenBinaryOperator
...as is used by GCC trunk libstdc++ std::unique_ptr since <https://gcc.gnu.org/ git/?p=gcc.git;a=commitdiff;h=5b074864f8c593fd4bccee788a023a37b446b2ed> "libstdc++: Add comparison operators to std::unique_ptr", which caused unexpected warnings like > sfx2/source/dialog/tabdlg.cxx:1057:17: error: parentheses immediately inside vardecl statement [loplugin:unnecessaryparen] > bool bSet = ( m_pSet != nullptr ); > ^~~~~~~~~~~~~~~~~~~~~ (CXXRewrittenBinaryOperator was introduced with <https://github.com/llvm/ llvm-project/commit/778dc0f1d49230f53401ae0c190fe460bda4ffd1> "[c++20] Add CXXRewrittenBinaryOperator to represent a comparison", which first appeared in LLVM 10.) Change-Id: I68024d975dc4accbfa9da855baa37bf9f990b99c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92061 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/unnecessaryparen.cxx5
1 files changed, 5 insertions, 0 deletions
diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx
index 106f2d2b3352..e93dfa64b5ec 100644
--- a/compilerplugins/clang/unnecessaryparen.cxx
+++ b/compilerplugins/clang/unnecessaryparen.cxx
@@ -468,6 +468,11 @@ bool UnnecessaryParen::VisitVarDecl(const VarDecl* varDecl)
// 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)) {
+ sub = e->getDecomposedForm().InnerBinOp;
+ }
+#endif
if (auto subBinOp = dyn_cast<BinaryOperator>(sub))
{
if (!(subBinOp->isMultiplicativeOp() || subBinOp->isAdditiveOp() || subBinOp->isPtrMemOp()))