summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-05-29 12:05:09 +0200
committerStephan Bergmann <sbergman@redhat.com>2015-05-29 12:05:09 +0200
commit0571f3c5033e1db38484632aca64376dd0b09cf5 (patch)
treed2a6fdd1a81d37efa1c434bad91897df0eaf6561 /compilerplugins
parent696f96f34b9e4cc384ecb3481b018301f493fc23 (diff)
loplugin:redundantcast: const_cast to same type
Change-Id: I1abdc2ab0b145e12f7fb00db529f52c11e4d7cfd
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/redundantcast.cxx19
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;