summaryrefslogtreecommitdiffstats
path: root/compilerplugins/clang/redundantcast.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-03-20 09:01:33 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-03-22 06:47:35 +0000
commit7299481834b15c920f996f4b0f3b5f821a82a10d (patch)
tree6cbc8a64399046dd2c83e4a4ef778c65ec00a34a /compilerplugins/clang/redundantcast.cxx
parentcreate SfxDisableFlags enum (diff)
downloadcore-7299481834b15c920f996f4b0f3b5f821a82a10d.tar.gz
core-7299481834b15c920f996f4b0f3b5f821a82a10d.zip
loplugin:redundantcast find redundant c-style enum casts
Change-Id: I2dab376d87804521aed6b6bd41ad7762830fa349 Reviewed-on: https://gerrit.libreoffice.org/35467 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/redundantcast.cxx')
-rw-r--r--compilerplugins/clang/redundantcast.cxx20
1 files changed, 20 insertions, 0 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx
index 0525fa51f584..4bef116f481b 100644
--- a/compilerplugins/clang/redundantcast.cxx
+++ b/compilerplugins/clang/redundantcast.cxx
@@ -138,6 +138,8 @@ public:
bool VisitCXXDeleteExpr(CXXDeleteExpr const * expr);
+ bool VisitCStyleCastExpr(CStyleCastExpr const * expr);
+
bool VisitBinSub(BinaryOperator const * expr)
{ return visitBinOp(expr); }
@@ -288,6 +290,24 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
return true;
}
+bool RedundantCast::VisitCStyleCastExpr(CStyleCastExpr const * expr) {
+ if (ignoreLocation(expr)) {
+ return true;
+ }
+ if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(expr->getLocStart()))) {
+ return true;
+ }
+ auto t1 = getSubExprAsWritten(expr)->getType();
+ auto t2 = expr->getTypeAsWritten();
+ if (loplugin::TypeCheck(t1).Enum() && loplugin::TypeCheck(t2).Enum() && t1 == t2) {
+ report(
+ DiagnosticsEngine::Warning,
+ "redundant cstyle enum cast from %0 to %1", expr->getExprLoc())
+ << t1 << t2 << expr->getSourceRange();
+ }
+ return true;
+}
+
bool RedundantCast::VisitCXXStaticCastExpr(CXXStaticCastExpr const * expr) {
if (ignoreLocation(expr)) {
return true;