diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-05-29 12:05:09 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-05-29 12:05:09 +0200 |
commit | 0571f3c5033e1db38484632aca64376dd0b09cf5 (patch) | |
tree | d2a6fdd1a81d37efa1c434bad91897df0eaf6561 /compilerplugins/clang | |
parent | 696f96f34b9e4cc384ecb3481b018301f493fc23 (diff) |
loplugin:redundantcast: const_cast to same type
Change-Id: I1abdc2ab0b145e12f7fb00db529f52c11e4d7cfd
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/redundantcast.cxx | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index 474dafa11e85..976e80e5495d 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -52,6 +52,8 @@ public: bool VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr const * expr); + bool VisitCXXConstCastExpr(CXXConstCastExpr const * expr); + bool VisitCallExpr(CallExpr const * expr); bool VisitCXXDeleteExpr(CXXDeleteExpr const * expr); @@ -263,6 +265,23 @@ bool RedundantCast::VisitCXXReinterpretCastExpr( return true; } +bool RedundantCast::VisitCXXConstCastExpr(CXXConstCastExpr const * expr) { + if (ignoreLocation(expr)) { + return true; + } + if (expr->getTypeAsWritten().getCanonicalType().getTypePtr() + == (expr->getSubExprAsWritten()->getType().getCanonicalType() + .getTypePtr())) + { + report( + DiagnosticsEngine::Warning, "redundant const_cast from %0 to %1", + expr->getExprLoc()) + << expr->getSubExprAsWritten()->getType() + << expr->getTypeAsWritten() << expr->getSourceRange(); + } + return true; +} + bool RedundantCast::VisitCallExpr(CallExpr const * expr) { if (ignoreLocation(expr)) { return true; |