diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-04 08:53:38 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-04 10:52:41 +0200 |
commit | 7aa7f4d9e4294959748bccf9e763154740251635 (patch) | |
tree | 79fc3855ce0cc1141abdda514df374cd42ab259c /compilerplugins | |
parent | 6f511a5de909b2fb6cb42b851e0cc90f54fbdd59 (diff) |
loplugin:unnecessaryparen include c++ casts
Change-Id: I132d3c66f0562e2c37a02eaf4c168d06c2b473eb
Reviewed-on: https://gerrit.libreoffice.org/41874
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/test/unnecessaryparen.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/unnecessaryparen.cxx | 20 |
2 files changed, 19 insertions, 4 deletions
diff --git a/compilerplugins/clang/test/unnecessaryparen.cxx b/compilerplugins/clang/test/unnecessaryparen.cxx index 85be13848b22..1ea22288673e 100644 --- a/compilerplugins/clang/test/unnecessaryparen.cxx +++ b/compilerplugins/clang/test/unnecessaryparen.cxx @@ -32,6 +32,9 @@ int main() // lots of our code uses this style, which I'm loathe to bulk-fix as yet int z = (y) ? 1 : 0; (void)z; + + int v1 = (static_cast<short>(1)) + 1; // expected-error {{unnecessary parentheses around cast [loplugin:unnecessaryparen]}} + (void)v1; }; /* 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 1e01c41d5893..7f0e532585c1 100644 --- a/compilerplugins/clang/unnecessaryparen.cxx +++ b/compilerplugins/clang/unnecessaryparen.cxx @@ -109,8 +109,10 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) if (insideConditionalOperator && parenExpr == insideConditionalOperator) return true; - auto subParenExpr = dyn_cast<ParenExpr>(parenExpr->getSubExpr()->IgnoreImpCasts()); - if (subParenExpr) { + auto subExpr = parenExpr->getSubExpr()->IgnoreImpCasts(); + + if (auto subParenExpr = dyn_cast<ParenExpr>(subExpr)) + { if (subParenExpr->getLocStart().isMacroID()) return true; report( @@ -119,8 +121,7 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) << parenExpr->getSourceRange(); } - auto declRefExpr = dyn_cast<DeclRefExpr>(parenExpr->getSubExpr()->IgnoreImpCasts()); - if (declRefExpr) { + if (auto declRefExpr = dyn_cast<DeclRefExpr>(subExpr)) { if (declRefExpr->getLocStart().isMacroID()) return true; @@ -136,6 +137,17 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) parenExpr->getLocStart()) << parenExpr->getSourceRange(); } + + + if (auto cxxNamedCastExpr = dyn_cast<CXXNamedCastExpr>(subExpr)) { + if (cxxNamedCastExpr->getLocStart().isMacroID()) + return true; + report( + DiagnosticsEngine::Warning, "unnecessary parentheses around cast", + parenExpr->getLocStart()) + << parenExpr->getSourceRange(); + } + return true; } |