summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-01-09 16:42:09 +0100
committerStephan Bergmann <sbergman@redhat.com>2015-01-09 16:42:42 +0100
commit31498259bb801dee7bb2d7cb2b40162876116aa4 (patch)
treebd59dee7607b636f052f8ad51f34d830aa52c2a4
parent97a8b3ed5e5bd42e213d3230fa764b0f5d10f0f2 (diff)
loplugin:cstylecast: warn about certain redundant reinterpret_casts
Change-Id: Iaa46849742c215798722d03d9ee59bb39d8033f7
-rw-r--r--binaryurp/source/unmarshal.cxx2
-rw-r--r--compilerplugins/clang/cstylecast.cxx28
2 files changed, 29 insertions, 1 deletions
diff --git a/binaryurp/source/unmarshal.cxx b/binaryurp/source/unmarshal.cxx
index d04c8893265d..f34bfd3b4eb6 100644
--- a/binaryurp/source/unmarshal.cxx
+++ b/binaryurp/source/unmarshal.cxx
@@ -465,7 +465,7 @@ BinaryAny Unmarshal::readSequence(css::uno::TypeDescription const & type) {
static_cast< sal_Sequence * >(buf)->elements + i * ctd.get()->nSize,
const_cast< void * >(as[i].getValue(ctd)), ctd.get(), 0);
}
- return BinaryAny(type, reinterpret_cast< sal_Sequence ** >(&buf));
+ return BinaryAny(type, &buf);
}
void Unmarshal::readMemberValues(
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");
}