diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-03-05 13:44:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-03-06 06:47:06 +0100 |
commit | a2e3705d8b3b05ae664d54b762d6ff72927d5e48 (patch) | |
tree | 6ac31f9c9b419b12dbf065845a6941c143f57e2c /compilerplugins | |
parent | remove sal_IntPtr in OfaMSFilterTabPage2 (diff) | |
download | core-a2e3705d8b3b05ae664d54b762d6ff72927d5e48.tar.gz core-a2e3705d8b3b05ae664d54b762d6ff72927d5e48.zip |
loplugin:unnecessaryparen improve member expression
Change-Id: I304621018cb1e2a47e478e86df4229bcf2176741
Reviewed-on: https://gerrit.libreoffice.org/68757
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/test/unnecessaryparen.cxx | 11 | ||||
-rw-r--r-- | compilerplugins/clang/unnecessaryparen.cxx | 8 |
2 files changed, 19 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/unnecessaryparen.cxx b/compilerplugins/clang/test/unnecessaryparen.cxx index e89da95df384..fb36052778b5 100644 --- a/compilerplugins/clang/test/unnecessaryparen.cxx +++ b/compilerplugins/clang/test/unnecessaryparen.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <memory> #include <string> #include <rtl/ustring.hxx> #include <o3tl/typed_flags_set.hxx> @@ -114,4 +115,14 @@ int main() (void)nBits; }; +class Foo2 +{ + int* p; + + int foo2() + { + return (p) ? 1 : 0; // expected-error {{unnecessary parentheses around member expr [loplugin:unnecessaryparen]}} + } +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx index 287c080afb13..119ee98e13a5 100644 --- a/compilerplugins/clang/unnecessaryparen.cxx +++ b/compilerplugins/clang/unnecessaryparen.cxx @@ -219,6 +219,14 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) << parenExpr->getSourceRange(); } handled_.insert(parenExpr); + } else if (auto memberExpr = dyn_cast<MemberExpr>(subExpr)) { + if (isa<CXXThisExpr>(ignoreAllImplicit(memberExpr->getBase()))) { + report( + DiagnosticsEngine::Warning, "unnecessary parentheses around member expr", + compat::getBeginLoc(parenExpr)) + << parenExpr->getSourceRange(); + handled_.insert(parenExpr); + } } return true; |