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>
This commit is contained in:
parent
1b6ecb1dc5
commit
41a967af06
11 changed files with 30 additions and 14 deletions
|
@ -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 )
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue