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

loplugin:redundantcast: reinterpret_cast to void*

Change-Id: I947b49cfb15f0e7d6ddfaae386656c70e4bd48ba
üst 4e871a9b
......@@ -207,45 +207,59 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
bool RedundantCast::VisitCXXReinterpretCastExpr(
CXXReinterpretCastExpr const * expr)
{
if (ignoreLocation(expr)
|| !expr->getSubExpr()->getType()->isVoidPointerType())
{
return true;
}
auto t = expr->getType()->getAs<PointerType>();
if (t == nullptr || !t->getPointeeType()->isObjectType()) {
if (ignoreLocation(expr)) {
return true;
}
if (rewriter != nullptr) {
auto loc = expr->getLocStart();
while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
if (expr->getSubExpr()->getType()->isVoidPointerType()) {
auto t = expr->getType()->getAs<PointerType>();
if (t == nullptr || !t->getPointeeType()->isObjectType()) {
return true;
}
if (compat::isMacroBodyExpansion(compiler, loc)) {
auto loc2 = expr->getLocEnd();
while (compiler.getSourceManager().isMacroArgExpansion(loc2)) {
loc2 = compiler.getSourceManager().getImmediateMacroCallerLoc(
loc2);
if (rewriter != nullptr) {
auto loc = expr->getLocStart();
while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(
loc);
}
if (compat::isMacroBodyExpansion(compiler, loc2)) {
//TODO: check loc, loc2 are in same macro body expansion
loc = compiler.getSourceManager().getSpellingLoc(loc);
if (compat::isMacroBodyExpansion(compiler, loc)) {
auto loc2 = expr->getLocEnd();
while (compiler.getSourceManager().isMacroArgExpansion(loc2)) {
loc2 = compiler.getSourceManager()
.getImmediateMacroCallerLoc(loc2);
}
if (compat::isMacroBodyExpansion(compiler, loc2)) {
//TODO: check loc, loc2 are in same macro body expansion
loc = compiler.getSourceManager().getSpellingLoc(loc);
}
}
auto s = compiler.getSourceManager().getCharacterData(loc);
auto n = Lexer::MeasureTokenLength(
loc, compiler.getSourceManager(), compiler.getLangOpts());
std::string tok(s, n);
if (tok == "reinterpret_cast" && replaceText(loc, n, "static_cast"))
{
return true;
}
}
auto s = compiler.getSourceManager().getCharacterData(loc);
auto n = Lexer::MeasureTokenLength(
loc, compiler.getSourceManager(), compiler.getLangOpts());
std::string tok(s, n);
if (tok == "reinterpret_cast" && replaceText(loc, n, "static_cast")) {
report(
DiagnosticsEngine::Warning,
"reinterpret_cast from %0 to %1 can be simplified to static_cast",
expr->getExprLoc())
<< expr->getSubExprAsWritten()->getType() << expr->getType()
<< expr->getSourceRange();
} else if (expr->getType()->isVoidPointerType()) {
auto t = expr->getSubExpr()->getType()->getAs<PointerType>();
if (t == nullptr || !t->getPointeeType()->isObjectType()) {
return true;
}
report(
DiagnosticsEngine::Warning,
("reinterpret_cast from %0 to %1 can be simplified to static_cast"
" or an implicit conversion"),
expr->getExprLoc())
<< expr->getSubExprAsWritten()->getType() << expr->getType()
<< expr->getSourceRange();
}
report(
DiagnosticsEngine::Warning,
"reinterpret_cast from %0 to %1 can be simplified to static_cast",
expr->getExprLoc())
<< expr->getSubExprAsWritten()->getType() << expr->getType()
<< expr->getSourceRange();
return true;
}
......
......@@ -242,7 +242,7 @@ extern "C" { static void s_releaseAndRevoke_v(va_list * pParam)
uno_ExtEnvironment * pEnv = va_arg(*pParam, uno_ExtEnvironment *);
uno_Interface * pUnoI = va_arg(*pParam, uno_Interface *);
pEnv->revokeInterface(pEnv, reinterpret_cast<void *>(pUnoI));
pEnv->revokeInterface(pEnv, pUnoI);
pUnoI->release(pUnoI);
}}
......
......@@ -176,7 +176,7 @@ void SAL_CALL OInterceptor::dispatch( const URL& _URL,const Sequence<PropertyVal
DispatchHelper* pHelper = new DispatchHelper;
pHelper->aArguments = Arguments;
pHelper->aURL = _URL;
Application::PostUserEvent( LINK( this, OInterceptor, OnDispatch ), reinterpret_cast< void* >( pHelper ) );
Application::PostUserEvent( LINK( this, OInterceptor, OnDispatch ), pHelper );
return;
}
}
......
......@@ -496,7 +496,7 @@ void OTasksWindow::fillTaskEntryList( const TaskEntryList& _rList )
for ( TaskEntryList::const_iterator pTask = _rList.begin(); pTask != aEnd; ++pTask, ++pImages )
{
SvTreeListEntry* pEntry = m_aCreation->InsertEntry( pTask->sTitle );
pEntry->SetUserData( reinterpret_cast< void* >( new TaskEntry( *pTask ) ) );
pEntry->SetUserData( new TaskEntry( *pTask ) );
Image aImage = Image( *pImages );
m_aCreation->SetExpandedEntryBmp( pEntry, aImage );
......
......@@ -927,7 +927,7 @@ OutlineToImpressFinalizer::OutlineToImpressFinalizer (
const ErrCode nErrorCode (
rBytes.ReadAt(
nReadPosition,
reinterpret_cast<void*>(pBuffer.get()),
pBuffer.get(),
nBufferSize,
&nReadByteCount));
......@@ -951,7 +951,7 @@ OutlineToImpressFinalizer::OutlineToImpressFinalizer (
// Append the read bytes to the end of the memory stream.
if (nReadByteCount > 0)
{
mpStream->Write(reinterpret_cast<void*>(pBuffer.get()), nReadByteCount);
mpStream->Write(pBuffer.get(), nReadByteCount);
nReadPosition += nReadByteCount;
}
}
......
......@@ -55,8 +55,7 @@ void PreviewValueSet::SetRightMouseClickHandler (const Link<>& rLink)
void PreviewValueSet::MouseButtonDown (const MouseEvent& rEvent)
{
if (rEvent.IsRight())
maRightMouseClickHandler.Call(reinterpret_cast<void*>(
&const_cast<MouseEvent&>(rEvent)));
maRightMouseClickHandler.Call(&const_cast<MouseEvent&>(rEvent));
else
ValueSet::MouseButtonDown (rEvent);
......
......@@ -590,7 +590,7 @@ namespace sfx2 {
}
#define NEW_ENTRY( url, bool ) \
reinterpret_cast<void*>( new IndexEntry_Impl( url, bool ) )
new IndexEntry_Impl( url, bool )
#define UNIFY_AND_INSERT_TOKEN( aToken ) \
it = aInfo.insert( sfx2::KeywordInfo::value_type( aToken, 0 ) ).first; \
......
......@@ -108,7 +108,7 @@ void recently_used_file::truncate(off_t length)
size_t recently_used_file::read(char* buffer, size_t size) const
{
size_t r = fread(reinterpret_cast<void*>(buffer), sizeof(char), size, file_);
size_t r = fread(buffer, sizeof(char), size, file_);
if ((r < size) && ferror(file_))
throw "I/O error: read failed";
......@@ -119,7 +119,7 @@ size_t recently_used_file::read(char* buffer, size_t size) const
void recently_used_file::write(const char* buffer, size_t size) const
{
if (size != fwrite(reinterpret_cast<const void*>(buffer), sizeof(char), size, file_))
if (size != fwrite(buffer, sizeof(char), size, file_))
throw "I/O error: write failed";
}
......
......@@ -396,7 +396,7 @@ OString GraphicObject::GetUniqueID() const
SvStream* GraphicObject::GetSwapStream() const
{
if( HasSwapStreamHdl() )
return reinterpret_cast<SvStream*>( mpSwapStreamHdl->Call( const_cast<void*>(reinterpret_cast<const void*>(this)) ) );
return reinterpret_cast<SvStream*>( mpSwapStreamHdl->Call( const_cast<void*>(static_cast<const void*>(this)) ) );
else
return GRFMGR_AUTOSWAPSTREAM_NONE;
}
......
......@@ -668,7 +668,7 @@ gboolean ensure_dbus_setup( gpointer data )
// Create menu model and action group attached to this frame.
GMenuModel* pMenuModel = G_MENU_MODEL( g_lo_menu_new() );
GActionGroup* pActionGroup = reinterpret_cast<GActionGroup*>(g_lo_action_group_new( reinterpret_cast< gpointer >( pSalFrame ) ));
GActionGroup* pActionGroup = reinterpret_cast<GActionGroup*>(g_lo_action_group_new( static_cast< gpointer >( pSalFrame ) ));
// Generate menu paths.
::Window windowId = GDK_WINDOW_XID( gdkWindow );
......
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