diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-01-09 16:42:09 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-01-09 16:42:42 +0100 |
commit | 31498259bb801dee7bb2d7cb2b40162876116aa4 (patch) | |
tree | bd59dee7607b636f052f8ad51f34d830aa52c2a4 /compilerplugins/clang/cstylecast.cxx | |
parent | 97a8b3ed5e5bd42e213d3230fa764b0f5d10f0f2 (diff) |
loplugin:cstylecast: warn about certain redundant reinterpret_casts
Change-Id: Iaa46849742c215798722d03d9ee59bb39d8033f7
Diffstat (limited to 'compilerplugins/clang/cstylecast.cxx')
-rw-r--r-- | compilerplugins/clang/cstylecast.cxx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/compilerplugins/clang/cstylecast.cxx b/compilerplugins/clang/cstylecast.cxx index 53b7d8802db6..4f8bd4bfbd37 100644 --- a/compilerplugins/clang/cstylecast.cxx +++ b/compilerplugins/clang/cstylecast.cxx @@ -47,6 +47,8 @@ public: bool VisitCStyleCastExpr(const CStyleCastExpr * expr); + bool VisitImplicitCastExpr(ImplicitCastExpr const * expr); + private: bool externCFunction; }; @@ -136,6 +138,32 @@ bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) { return true; } +bool CStyleCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) { + if (ignoreLocation(expr) || expr->getCastKind() != CK_BitCast) { + return true; + } + QualType t = expr->getType(); + if (!(t->isPointerType() + && t->getAs<PointerType>()->getPointeeType()->isVoidType() + && expr->getSubExpr()->getType()->isPointerType())) + { + return true; + } + Expr const * e = expr->getSubExpr()->IgnoreParenImpCasts(); + while (isa<CXXConstCastExpr>(e)) { + e = dyn_cast<CXXConstCastExpr>(e)->getSubExpr()->IgnoreParenImpCasts(); + } + if (isa<CXXReinterpretCastExpr>(e)) { + report( + DiagnosticsEngine::Warning, + ("redundant reinterpret_cast, result is implicitly cast to void" + " pointer"), + e->getExprLoc()) + << e->getSourceRange(); + } + return true; +} + loplugin::Plugin::Registration< CStyleCast > X("cstylecast"); } |