diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-05-18 09:51:46 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-05-18 10:52:59 +0200 |
commit | 41a967af06a9584a997e11079c3c931d34158c09 (patch) | |
tree | 494ca16d2d6148ad54ceacec4ab170f57efd8dd2 | |
parent | 1b6ecb1dc544b7a462948a1c85d4bfc6f08865b8 (diff) |
Extend loplugin:redundantcast to trivial reinterpret_cast from T to itself
Change-Id: I7c0be7b435d6b5f97bdd40484023584146638d70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134506
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | basic/source/classes/sbxmod.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/redundantcast.cxx | 10 | ||||
-rw-r--r-- | compilerplugins/clang/test/redundantcast.cxx | 6 | ||||
-rw-r--r-- | sal/qa/rtl/textenc/rtl_textcvt.cxx | 2 | ||||
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/tox/txmsrt.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/txtnode/swfont.cxx | 8 | ||||
-rw-r--r-- | unoxml/source/dom/node.cxx | 2 | ||||
-rw-r--r-- | unoxml/source/rdf/librdf_repository.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/generic/window/salframe.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtkinst.cxx | 2 |
11 files changed, 30 insertions, 14 deletions
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index 67bf03ef9ecb..1e5e7ec36a7f 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -1450,7 +1450,7 @@ const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine, const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine, sal_uInt16& nCol, bool bFollowJumps, const SbiImage* pImg ) const { - sal_uInt32 nPC = static_cast<sal_uInt32>( p - reinterpret_cast<const sal_uInt8*>(pImage->GetCode()) ); + sal_uInt32 nPC = static_cast<sal_uInt32>( p - pImage->GetCode() ); while( nPC < pImage->GetCodeSize() ) { SbiOpcode eOp = static_cast<SbiOpcode>( *p++ ); @@ -1460,7 +1460,7 @@ const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine, SAL_WARN_IF( !pImg, "basic", "FindNextStmnt: pImg==NULL with FollowJumps option" ); sal_uInt32 nOp1 = *p++; nOp1 |= *p++ << 8; nOp1 |= *p++ << 16; nOp1 |= *p++ << 24; - p = reinterpret_cast<const sal_uInt8*>(pImg->GetCode()) + nOp1; + p = pImg->GetCode() + nOp1; } else if( eOp >= SbiOpcode::SbOP1_START && eOp <= SbiOpcode::SbOP1_END ) { @@ -1497,7 +1497,7 @@ bool SbModule::IsBreakable( sal_uInt16 nLine ) const { if( !pImage ) return false; - const sal_uInt8* p = reinterpret_cast<const sal_uInt8*>(pImage->GetCode()); + const sal_uInt8* p = pImage->GetCode(); sal_uInt16 nl, nc; while( ( p = FindNextStmnt( p, nl, nc ) ) != nullptr ) if( nl == nLine ) diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index 1cfe44c9305e..87c4d14458fd 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -577,6 +577,16 @@ bool RedundantCast::VisitCXXReinterpretCastExpr( if (ignoreLocation(expr)) { return true; } + if (expr->getTypeAsWritten() == expr->getSubExprAsWritten()->getType()) + //TODO: instead of exact QualType match, allow some variation? + { + report( + DiagnosticsEngine::Warning, "redundant reinterpret_cast from %0 to %1", + expr->getExprLoc()) + << expr->getSubExprAsWritten()->getType() << expr->getTypeAsWritten() + << expr->getSourceRange(); + return true; + } if (auto const sub = dyn_cast<ImplicitCastExpr>(expr->getSubExpr())) { if (sub->getCastKind() == CK_ArrayToPointerDecay && sub->getType() == expr->getType()) //TODO: instead of exact QualType match, allow some variation? diff --git a/compilerplugins/clang/test/redundantcast.cxx b/compilerplugins/clang/test/redundantcast.cxx index d1803aafbca7..7a102cca5d0a 100644 --- a/compilerplugins/clang/test/redundantcast.cxx +++ b/compilerplugins/clang/test/redundantcast.cxx @@ -329,6 +329,11 @@ void testArithmeticTypedefs() { (void) static_cast<T1>(c); // expected-error {{redundant}} } +void testReinterpretCast() { + int * p; + (void) reinterpret_cast<int *>(p); // expected-error {{redundant reinterpret_cast from 'int *' to 'int *' [loplugin:redundantcast]}} +} + void testReinterpretConstCast() { int n = 0; (void) reinterpret_cast<std::size_t>((const_cast<int const *>(&n))); // expected-error-re {{redundant const_cast from 'int *' to 'const int *' within reinterpret_cast to fundamental type 'std::size_t' (aka 'unsigned {{.+}}') [loplugin:redundantcast]}} @@ -442,6 +447,7 @@ int main() { testFunctionalCast(); testCStyleCast(); testCStyleCastOfTemplateMethodResult(nullptr); + testReinterpretCast(); testReinterpretConstCast(); testDynamicCast(); testIntermediaryStaticCast(); diff --git a/sal/qa/rtl/textenc/rtl_textcvt.cxx b/sal/qa/rtl/textenc/rtl_textcvt.cxx index 8fa8b4e8dc96..55804bd32838 100644 --- a/sal/qa/rtl/textenc/rtl_textcvt.cxx +++ b/sal/qa/rtl/textenc/rtl_textcvt.cxx @@ -260,7 +260,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) { sal_Size nConverted; sal_Size nSize = rtl_convertTextToUnicode( aConverter, aContext, - reinterpret_cast< char const * >(rTest.m_pText + nInput), + rTest.m_pText + nInput, nSrcBytes, aUnicode + nOutput, TEST_STRING_SIZE - nOutput, nFlags, &nInfo, &nConverted); nOutput += nSize; diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 7bfb30a7a544..e9f3f012bc6c 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -390,7 +390,7 @@ xmlDocUniquePtr SdTiledRenderingTest::parseXmlDump() (void)xmlTextWriterEndDocument(pXmlWriter); xmlFreeTextWriter(pXmlWriter); - auto pCharBuffer = reinterpret_cast<const xmlChar*>(xmlBufferContent(m_pXmlBuffer)); + auto pCharBuffer = xmlBufferContent(m_pXmlBuffer); SAL_INFO("test", "SdTiledRenderingTest::parseXmlDump: pCharBuffer is '" << pCharBuffer << "'"); return xmlDocUniquePtr(xmlParseDoc(pCharBuffer)); } diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx index b0195ff8d718..8e2272b1ff8a 100644 --- a/sw/source/core/tox/txmsrt.cxx +++ b/sw/source/core/tox/txmsrt.cxx @@ -753,7 +753,7 @@ TextAndReading SwTOXTable::GetText_Impl(SwRootFrame const*const) const if( pNd ) { const SwTableNode* pTableNd = - reinterpret_cast<const SwTableNode*>(pNd->FindTableNode()); + pNd->FindTableNode(); if (pTableNd) { return TextAndReading(pTableNd->GetTable().GetFrameFormat()->GetName(), OUString()); diff --git a/sw/source/core/txtnode/swfont.cxx b/sw/source/core/txtnode/swfont.cxx index 30cd44851081..0ed7baf87894 100644 --- a/sw/source/core/txtnode/swfont.cxx +++ b/sw/source/core/txtnode/swfont.cxx @@ -975,7 +975,7 @@ Size SwSubFont::GetTextSize_( SwDrawTextInfo& rInf ) { // Robust: the font is supposed to be set already, but better safe than // sorry... - if ( !pLastFont || pLastFont->GetOwner() != reinterpret_cast<const void*>(m_nFontCacheId) || + if ( !pLastFont || pLastFont->GetOwner() != m_nFontCacheId || !IsSameInstance( rInf.GetpOut()->GetFont() ) ) ChgFnt( rInf.GetShell(), rInf.GetOut() ); @@ -1093,7 +1093,7 @@ void SwSubFont::DrawText_( SwDrawTextInfo &rInf, const bool bGrey ) pUnderFnt = rInf.GetUnderFnt(); } - if( !pLastFont || pLastFont->GetOwner() != reinterpret_cast<const void*>(m_nFontCacheId) ) + if( !pLastFont || pLastFont->GetOwner() != m_nFontCacheId ) ChgFnt( rInf.GetShell(), rInf.GetOut() ); SwDigitModeModifier aDigitModeModifier( rInf.GetOut(), rInf.GetFont()->GetLanguage() ); @@ -1218,7 +1218,7 @@ void SwSubFont::DrawStretchText_( SwDrawTextInfo &rInf ) pUnderFnt = rInf.GetUnderFnt(); } - if ( !pLastFont || pLastFont->GetOwner() != reinterpret_cast<const void*>(m_nFontCacheId) ) + if ( !pLastFont || pLastFont->GetOwner() != m_nFontCacheId ) ChgFnt( rInf.GetShell(), rInf.GetOut() ); SwDigitModeModifier aDigitModeModifier( rInf.GetOut(), rInf.GetFont()->GetLanguage() ); @@ -1283,7 +1283,7 @@ void SwSubFont::DrawStretchText_( SwDrawTextInfo &rInf ) TextFrameIndex SwSubFont::GetModelPositionForViewPoint_( SwDrawTextInfo& rInf ) { - if ( !pLastFont || pLastFont->GetOwner() != reinterpret_cast<const void*>(m_nFontCacheId) ) + if ( !pLastFont || pLastFont->GetOwner() != m_nFontCacheId ) ChgFnt( rInf.GetShell(), rInf.GetOut() ); SwDigitModeModifier aDigitModeModifier( rInf.GetOut(), rInf.GetFont()->GetLanguage() ); diff --git a/unoxml/source/dom/node.cxx b/unoxml/source/dom/node.cxx index f39aba6bd079..235af0bc5e0d 100644 --- a/unoxml/source/dom/node.cxx +++ b/unoxml/source/dom/node.cxx @@ -101,7 +101,7 @@ namespace DOM { sal_Int32 nNamespaceToken = FastToken::DONTKNOW; OString prefix(pPrefix, - strlen(reinterpret_cast<const char*>(pPrefix))); + strlen(pPrefix)); SAL_INFO("unoxml", "getTokenWithPrefix(): prefix " << pPrefix << ", name " << pName); diff --git a/unoxml/source/rdf/librdf_repository.cxx b/unoxml/source/rdf/librdf_repository.cxx index 63654e09efdd..169f9550f0ea 100644 --- a/unoxml/source/rdf/librdf_repository.cxx +++ b/unoxml/source/rdf/librdf_repository.cxx @@ -2426,7 +2426,7 @@ librdf_TypeConverter::convertToXNode(librdf_node* i_pNode) const RTL_TEXTENCODING_UTF8) ); if (lang) { const OUString langU( OStringToOUString( - std::string_view(reinterpret_cast<const char*>(lang)), + std::string_view(lang), RTL_TEXTENCODING_UTF8) ); return rdf::Literal::createWithLanguage(m_xContext, valueU, langU); } else if (pType) { diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index 8c2d67c70565..943aa3d527f7 100644 --- a/vcl/unx/generic/window/salframe.cxx +++ b/vcl/unx/generic/window/salframe.cxx @@ -3204,7 +3204,7 @@ bool X11SalFrame::HandleKeyEvent( XKeyEvent *pEvent ) // convert to single byte text stream nSize = rtl_convertTextToUnicode( aConverter, aContext, - reinterpret_cast<char*>(pPrintable), nLen, + pPrintable, nLen, pBuffer, nBufferSize, RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE | RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE, diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 12ded5210ef0..86f8bb3af99d 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -22338,7 +22338,7 @@ private: if (!pMouseEnteredAnotherPopup) return false; - return gtk_widget_event(pEventWidget, reinterpret_cast<GdkEvent*>(pEvent)); + return gtk_widget_event(pEventWidget, pEvent); } static gboolean signalButtonCrossing(GtkWidget*, GdkEvent* pEvent, gpointer widget) |