diff options
-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; |