summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/redundantcast.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/redundantcast.cxx')
-rw-r--r--compilerplugins/clang/redundantcast.cxx17
1 files changed, 17 insertions, 0 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx
index 0faadc5a541a..66b81941e579 100644
--- a/compilerplugins/clang/redundantcast.cxx
+++ b/compilerplugins/clang/redundantcast.cxx
@@ -248,6 +248,23 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
}
}
break;
+ case CK_FloatingToIntegral:
+ case CK_IntegralToFloating:
+ if (auto e = dyn_cast<ExplicitCastExpr>(expr->getSubExpr()->IgnoreParenImpCasts())) {
+ if ((isa<CXXStaticCastExpr>(e) || isa<CXXFunctionalCastExpr>(e))
+ && (e->getSubExprAsWritten()->getType().getCanonicalType().getTypePtr()
+ == expr->getType().getCanonicalType().getTypePtr()))
+ {
+ report(
+ DiagnosticsEngine::Warning,
+ ("suspicious %select{static_cast|functional cast}0 from %1 to %2, result is"
+ " implicitly cast to %3"),
+ e->getExprLoc())
+ << isa<CXXFunctionalCastExpr>(e) << e->getSubExprAsWritten()->getType()
+ << e->getTypeAsWritten() << expr->getType() << expr->getSourceRange();
+ }
+ }
+ break;
default:
break;
}