Kaydet (Commit) 31498259 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

loplugin:cstylecast: warn about certain redundant reinterpret_casts

Change-Id: Iaa46849742c215798722d03d9ee59bb39d8033f7
üst 97a8b3ed
...@@ -465,7 +465,7 @@ BinaryAny Unmarshal::readSequence(css::uno::TypeDescription const & type) { ...@@ -465,7 +465,7 @@ BinaryAny Unmarshal::readSequence(css::uno::TypeDescription const & type) {
static_cast< sal_Sequence * >(buf)->elements + i * ctd.get()->nSize, static_cast< sal_Sequence * >(buf)->elements + i * ctd.get()->nSize,
const_cast< void * >(as[i].getValue(ctd)), ctd.get(), 0); 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( void Unmarshal::readMemberValues(
......
...@@ -47,6 +47,8 @@ public: ...@@ -47,6 +47,8 @@ public:
bool VisitCStyleCastExpr(const CStyleCastExpr * expr); bool VisitCStyleCastExpr(const CStyleCastExpr * expr);
bool VisitImplicitCastExpr(ImplicitCastExpr const * expr);
private: private:
bool externCFunction; bool externCFunction;
}; };
...@@ -136,6 +138,32 @@ bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) { ...@@ -136,6 +138,32 @@ bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) {
return true; 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"); loplugin::Plugin::Registration< CStyleCast > X("cstylecast");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment