[Libreoffice-commits] core.git: compilerplugins/clang sc/source starmath/source svx/source sw/source vcl/source

Noel (via logerrit) logerrit at kemper.freedesktop.org
Sun Mar 7 12:23:07 UTC 2021


 compilerplugins/clang/staticdynamic.cxx      |   26 ++++++++++++++++++--------
 compilerplugins/clang/test/staticdynamic.cxx |   10 +++++++++-
 sc/source/core/tool/interpr4.cxx             |    9 +++++++--
 starmath/source/edit.cxx                     |    5 ++---
 svx/source/engine3d/view3d.cxx               |    5 +++--
 svx/source/form/fmview.cxx                   |    6 +++---
 svx/source/form/navigatortree.cxx            |    8 ++++----
 svx/source/sidebar/SelectionAnalyzer.cxx     |    8 ++++----
 svx/source/svdraw/svdmrkv.cxx                |    3 ++-
 svx/source/unodraw/UnoGraphicExporter.cxx    |    6 +++---
 sw/source/core/access/acccontext.cxx         |    8 ++------
 sw/source/core/access/accdoc.cxx             |    4 +---
 sw/source/core/access/accframebase.cxx       |    3 +--
 sw/source/core/access/accpara.cxx            |    3 +--
 sw/source/core/doc/docfly.cxx                |    9 ++++-----
 sw/source/core/docnode/section.cxx           |   14 +++++++-------
 sw/source/core/layout/frmtool.cxx            |    7 ++++---
 sw/source/core/layout/layact.cxx             |   12 ++++++------
 sw/source/core/text/txtftn.cxx               |    5 +++--
 sw/source/uibase/uiview/viewdraw.cxx         |   21 +++++++++++----------
 vcl/source/edit/textundo.cxx                 |    5 ++---
 21 files changed, 97 insertions(+), 80 deletions(-)

New commits:
commit e4e80ed313882f9ea1b309054e5aa3e839586516
Author:     Noel <noel.grandin at collabora.co.uk>
AuthorDate: Sat Mar 6 20:40:58 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Mar 7 13:22:28 2021 +0100

    loplugin:staticdynamic now with extra salt
    
    because it wasn't quite there yet - now checks for casts with and
    without const, because const doesn't really matter here.
    
    Change-Id: I319025b2095a803fcaad2a7a696d2730b7fd2f81
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112098
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/staticdynamic.cxx b/compilerplugins/clang/staticdynamic.cxx
index b104b0333fcd..7f3d2bd49aed 100644
--- a/compilerplugins/clang/staticdynamic.cxx
+++ b/compilerplugins/clang/staticdynamic.cxx
@@ -80,6 +80,18 @@ bool StaticDynamic::TraverseCompoundStmt(CompoundStmt* compoundStmt)
     return ret;
 }
 
+const clang::Type* strip(QualType qt)
+{
+    const clang::Type* varType = qt->getUnqualifiedDesugaredType();
+    if (varType->isPointerType())
+        varType = varType->getPointeeType()->getUnqualifiedDesugaredType();
+    if (varType->isReferenceType())
+        varType = varType->getAs<clang::ReferenceType>()
+                      ->getPointeeType()
+                      ->getUnqualifiedDesugaredType();
+    return varType;
+}
+
 bool StaticDynamic::VisitCXXStaticCastExpr(CXXStaticCastExpr const* staticCastExpr)
 {
     if (ignoreLocation(staticCastExpr))
@@ -90,8 +102,8 @@ bool StaticDynamic::VisitCXXStaticCastExpr(CXXStaticCastExpr const* staticCastEx
     auto varDecl = dyn_cast_or_null<VarDecl>(subExprDecl->getDecl());
     if (!varDecl)
         return true;
-    auto it = blockState.dynamicCastVars.find(
-        { varDecl, staticCastExpr->getTypeAsWritten().getTypePtr() });
+    auto varType = strip(staticCastExpr->getType());
+    auto it = blockState.dynamicCastVars.find({ varDecl, varType });
     if (it != blockState.dynamicCastVars.end())
     {
         StringRef fn = getFilenameOfLocation(
@@ -110,8 +122,7 @@ bool StaticDynamic::VisitCXXStaticCastExpr(CXXStaticCastExpr const* staticCastEx
         report(DiagnosticsEngine::Note, "dynamic_cast here", it->second);
         return true;
     }
-    blockState.staticCastVars.insert({ { varDecl, staticCastExpr->getTypeAsWritten().getTypePtr() },
-                                       compat::getBeginLoc(staticCastExpr) });
+    blockState.staticCastVars.insert({ { varDecl, varType }, compat::getBeginLoc(staticCastExpr) });
     return true;
 }
 
@@ -126,8 +137,8 @@ bool StaticDynamic::VisitCXXDynamicCastExpr(CXXDynamicCastExpr const* dynamicCas
     auto varDecl = dyn_cast_or_null<VarDecl>(subExprDecl->getDecl());
     if (!varDecl)
         return true;
-    auto it = blockState.staticCastVars.find(
-        { varDecl, dynamicCastExpr->getTypeAsWritten().getTypePtr() });
+    auto varType = strip(dynamicCastExpr->getTypeAsWritten());
+    auto it = blockState.staticCastVars.find({ varDecl, varType });
     if (it != blockState.staticCastVars.end())
     {
         report(DiagnosticsEngine::Warning, "dynamic_cast after static_cast",
@@ -145,8 +156,7 @@ bool StaticDynamic::VisitCXXDynamicCastExpr(CXXDynamicCastExpr const* dynamicCas
         return true;
     }
     blockState.dynamicCastVars.insert(
-        { { varDecl, dynamicCastExpr->getTypeAsWritten().getTypePtr() },
-          compat::getBeginLoc(dynamicCastExpr) });
+        { { varDecl, varType }, compat::getBeginLoc(dynamicCastExpr) });
     return true;
 }
 
diff --git a/compilerplugins/clang/test/staticdynamic.cxx b/compilerplugins/clang/test/staticdynamic.cxx
index d700ea06c435..aa6ca7559b6b 100644
--- a/compilerplugins/clang/test/staticdynamic.cxx
+++ b/compilerplugins/clang/test/staticdynamic.cxx
@@ -14,7 +14,7 @@ struct ClassA
 
 struct ClassB : public ClassA
 {
-    void foo() {}
+    void foo() const {}
 };
 
 void f1(ClassA* p1)
@@ -33,4 +33,12 @@ void f2(ClassA* p1)
     static_cast<ClassB*>(p1)->foo();
 };
 
+void f3(ClassA* p1)
+{
+    // expected-note at +1 {{dynamic_cast here [loplugin:staticdynamic]}}
+    dynamic_cast<const ClassB*>(p1)->foo();
+    // expected-error at +1 {{static_cast after dynamic_cast [loplugin:staticdynamic]}}
+    static_cast<ClassB*>(p1)->foo();
+};
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index e71f5ebfe2fa..08c1c218748d 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -3225,14 +3225,19 @@ void ScInterpreter::ScMacro()
     }
 
     SbxVariable* pVar = pRoot ? pRoot->Find(aMacro, SbxClassType::Method) : nullptr;
-    if( !pVar || pVar->GetType() == SbxVOID || dynamic_cast<const SbMethod*>( pVar) ==  nullptr )
+    if( !pVar || pVar->GetType() == SbxVOID )
+    {
+        PushError( FormulaError::NoMacro );
+        return;
+    }
+    SbMethod* pMethod = dynamic_cast<SbMethod*>(pVar);
+    if( !pMethod )
     {
         PushError( FormulaError::NoMacro );
         return;
     }
 
     bool bVolatileMacro = false;
-    SbMethod* pMethod = static_cast<SbMethod*>(pVar);
 
     SbModule* pModule = pMethod->GetModule();
     bool bUseVBAObjects = pModule->IsVBACompat();
diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx
index d77433a7df8e..27d33f889dfb 100644
--- a/starmath/source/edit.cxx
+++ b/starmath/source/edit.cxx
@@ -467,9 +467,8 @@ void SmEditWindow::KeyInput(const KeyEvent& rKEvt)
             {
                 // SFX has maybe called a slot of the view and thus (because of a hack in SFX)
                 // set the focus to the view
-                SfxViewShell* pVShell = GetView();
-                if ( dynamic_cast<const SmViewShell *>(pVShell) &&
-                     static_cast<SmViewShell*>(pVShell)->GetGraphicWindow().HasFocus() )
+                SmViewShell* pVShell = GetView();
+                if ( pVShell && pVShell->GetGraphicWindow().HasFocus() )
                 {
                     GrabFocus();
                 }
diff --git a/svx/source/engine3d/view3d.cxx b/svx/source/engine3d/view3d.cxx
index e1cc81e5ad5d..4ab95d4b5ca2 100644
--- a/svx/source/engine3d/view3d.cxx
+++ b/svx/source/engine3d/view3d.cxx
@@ -662,7 +662,8 @@ void E3dView::ImpChangeSomeAttributesFor3DConversion(SdrObject* pObj)
 
 void E3dView::ImpChangeSomeAttributesFor3DConversion2(SdrObject* pObj)
 {
-    if(dynamic_cast<const SdrPathObj*>( pObj) ==  nullptr)
+    auto pPathObj = dynamic_cast<const SdrPathObj*>( pObj);
+    if(!pPathObj)
         return;
 
     const SfxItemSet& rSet = pObj->GetMergedItemSet();
@@ -670,7 +671,7 @@ void E3dView::ImpChangeSomeAttributesFor3DConversion2(SdrObject* pObj)
     drawing::LineStyle eLineStyle = rSet.Get(XATTR_LINESTYLE).GetValue();
     drawing::FillStyle eFillStyle = rSet.Get(XATTR_FILLSTYLE).GetValue();
 
-    if(static_cast<SdrPathObj*>(pObj)->IsClosed()
+    if(pPathObj->IsClosed()
         && eLineStyle == drawing::LineStyle_SOLID
         && !nLineWidth
         && eFillStyle != drawing::FillStyle_NONE)
diff --git a/svx/source/form/fmview.cxx b/svx/source/form/fmview.cxx
index b8a0ed479719..756fa8d2b21e 100644
--- a/svx/source/form/fmview.cxx
+++ b/svx/source/form/fmview.cxx
@@ -76,9 +76,9 @@ void FmFormView::Init()
     SdrModel* pModel = GetModel();
 
     DBG_ASSERT( dynamic_cast<const FmFormModel*>( pModel) !=  nullptr, "Wrong model" );
-    if( dynamic_cast<const FmFormModel*>( pModel) ==  nullptr ) return;
-    FmFormModel* pFormModel = static_cast<FmFormModel*>(pModel);
-
+    FmFormModel* pFormModel = dynamic_cast<FmFormModel*>(pModel);
+    if( !pFormModel )
+        return;
 
     // get DesignMode from model
     bool bInitDesignMode = pFormModel->GetOpenInDesignMode();
diff --git a/svx/source/form/navigatortree.cxx b/svx/source/form/navigatortree.cxx
index 5cde1645f4cf..bade46460186 100644
--- a/svx/source/form/navigatortree.cxx
+++ b/svx/source/form/navigatortree.cxx
@@ -1602,19 +1602,19 @@ namespace svxform
             FmEntryData* pCurrent = reinterpret_cast<FmEntryData*>(m_xTreeView->get_id(*rIter).toInt64());
 
             // a form ?
-            bool bIsForm = dynamic_cast<const FmFormData*>( pCurrent) !=  nullptr;
+            auto pFormData = dynamic_cast<FmFormData*>(pCurrent);
 
             // because deletion is done by the view, and i build on its MarkList,
             // but normally only direct controls, no indirect ones, are marked in a marked form,
             // I have to do it later
-            if (bIsForm)
-                MarkViewObj(static_cast<FmFormData*>(pCurrent), true/*deep*/);
+            if (pFormData)
+                MarkViewObj(pFormData, true/*deep*/);
 
             // a hidden control ?
             bool bIsHidden = IsHiddenControl(pCurrent);
 
             // keep forms and hidden controls, the rest not
-            if (!bIsForm && !bIsHidden)
+            if (!pFormData && !bIsHidden)
             {
                 // well, no form and no hidden control -> we can remove it from m_arrCurrentSelection, as it will
                 // be deleted automatically. This is because for every model (except forms and hidden control models)
diff --git a/svx/source/sidebar/SelectionAnalyzer.cxx b/svx/source/sidebar/SelectionAnalyzer.cxx
index 418940dc7334..7cc20c5dd0a0 100644
--- a/svx/source/sidebar/SelectionAnalyzer.cxx
+++ b/svx/source/sidebar/SelectionAnalyzer.cxx
@@ -41,8 +41,8 @@ EnumContext::Context SelectionAnalyzer::GetContextForSelection_SC(const SdrMarkL
         case 1:
         {
             SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
-            if (dynamic_cast<const SdrTextObj*>(pObj) != nullptr
-                && static_cast<SdrTextObj*>(pObj)->IsInEditMode())
+            auto pTextObj = dynamic_cast<SdrTextObj*>(pObj);
+            if (pTextObj && pTextObj->IsInEditMode())
             {
                 eContext = EnumContext::Context::DrawText;
             }
@@ -120,8 +120,8 @@ EnumContext::Context SelectionAnalyzer::GetContextForSelection_SD(const SdrMarkL
         case 1:
         {
             SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
-            if (dynamic_cast<const SdrTextObj*>(pObj) != nullptr
-                && static_cast<SdrTextObj*>(pObj)->IsInEditMode())
+            auto pTextObj = dynamic_cast<SdrTextObj*>(pObj);
+            if (pTextObj && pTextObj->IsInEditMode())
             {
                 if (pObj->GetObjIdentifier() == OBJ_TABLE)
                 {
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index 216d2c043709..3e4c9c21b8b2 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -2133,7 +2133,8 @@ SdrObject* SdrMarkView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nT
     const bool bCheckIfMarkable(nOptions & SdrSearchOptions::TESTMARKABLE);
     const bool bDeep(nOptions & SdrSearchOptions::DEEP);
     const bool bOLE(dynamic_cast< const SdrOle2Obj* >(pObj) !=  nullptr);
-    const bool bTXT(dynamic_cast<const SdrTextObj*>( pObj) != nullptr && static_cast<SdrTextObj*>(pObj)->IsTextFrame());
+    auto pTextObj = dynamic_cast<const SdrTextObj*>( pObj);
+    const bool bTXT(pTextObj && pTextObj->IsTextFrame());
     SdrObject* pRet=nullptr;
     tools::Rectangle aRect(pObj->GetCurrentBoundRect());
 
diff --git a/svx/source/unodraw/UnoGraphicExporter.cxx b/svx/source/unodraw/UnoGraphicExporter.cxx
index fcf9a39e4ca3..a177b84e214c 100644
--- a/svx/source/unodraw/UnoGraphicExporter.cxx
+++ b/svx/source/unodraw/UnoGraphicExporter.cxx
@@ -844,14 +844,14 @@ bool GraphicExporter::GetGraphic( ExportSettings const & rSettings, Graphic& aGr
             else if( rSettings.mbScrollText )
             {
                 SdrObject* pObj = aShapes.front();
-                if( dynamic_cast<const SdrTextObj*>( pObj)
-                    && static_cast<SdrTextObj*>(pObj)->HasText() )
+                auto pTextObj = dynamic_cast<SdrTextObj*>( pObj);
+                if( pTextObj && pTextObj->HasText() )
                 {
                     tools::Rectangle aScrollRectangle;
                     tools::Rectangle aPaintRectangle;
 
                     const std::unique_ptr< GDIMetaFile > pMtf(
-                        static_cast<SdrTextObj*>(pObj)->GetTextScrollMetaFileAndRectangle(
+                        pTextObj->GetTextScrollMetaFileAndRectangle(
                            aScrollRectangle, aPaintRectangle ) );
 
                     // take the larger one of the two rectangles (that
diff --git a/sw/source/core/access/acccontext.cxx b/sw/source/core/access/acccontext.cxx
index 78b9371f5a7e..bb59f3a68044 100644
--- a/sw/source/core/access/acccontext.cxx
+++ b/sw/source/core/access/acccontext.cxx
@@ -1385,16 +1385,12 @@ bool SwAccessibleContext::Select( SwPaM *pPaM, SdrObject *pObj,
     if( !pCursorShell )
         return false;
 
-    SwFEShell* pFEShell = dynamic_cast<const SwFEShell*>( pCursorShell) !=  nullptr
-                                ? static_cast<SwFEShell*>( pCursorShell )
-                                : nullptr;
+    SwFEShell* pFEShell = dynamic_cast<SwFEShell*>(pCursorShell);
     // Get rid of activated OLE object
     if( pFEShell )
         pFEShell->FinishOLEObj();
 
-    SwWrtShell* pWrtShell = dynamic_cast<const SwWrtShell*>( pCursorShell) !=  nullptr
-                                ? static_cast<SwWrtShell*>( pCursorShell )
-                                : nullptr;
+    SwWrtShell* pWrtShell = dynamic_cast<SwWrtShell*>(pCursorShell);
 
     bool bRet = false;
     if( pObj )
diff --git a/sw/source/core/access/accdoc.cxx b/sw/source/core/access/accdoc.cxx
index 7d920afc7d17..2643877038d0 100644
--- a/sw/source/core/access/accdoc.cxx
+++ b/sw/source/core/access/accdoc.cxx
@@ -520,9 +520,7 @@ uno::Any SAL_CALL SwAccessibleDocument::getExtendedAttributes()
     if( !pCursorShell )
         return anyAttribute;
 
-    SwFEShell* pFEShell = dynamic_cast<const SwFEShell*>( pCursorShell) !=  nullptr
-                                ? static_cast<SwFEShell*>( pCursorShell )
-                            : nullptr;
+    SwFEShell* pFEShell = dynamic_cast<SwFEShell*>(pCursorShell);
     if( pFEShell )
     {
         OUString sDisplay;
diff --git a/sw/source/core/access/accframebase.cxx b/sw/source/core/access/accframebase.cxx
index 6338ee18a5c1..c078bc2385f7 100644
--- a/sw/source/core/access/accframebase.cxx
+++ b/sw/source/core/access/accframebase.cxx
@@ -257,8 +257,7 @@ SwPaM* SwAccessibleFrameBase::GetCursor()
     SwCursorShell* pCursorShell = GetCursorShell();
     if( pCursorShell != nullptr && !pCursorShell->IsTableMode() )
     {
-        SwFEShell *pFESh = dynamic_cast<const SwFEShell*>( pCursorShell) !=  nullptr
-                            ? static_cast< SwFEShell * >( pCursorShell ) : nullptr;
+        SwFEShell *pFESh = dynamic_cast<SwFEShell*>( pCursorShell);
         if( !pFESh ||
             !(pFESh->IsFrameSelected() || pFESh->IsObjSelected() > 0) )
         {
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 67b97f784282..f8e9ac6d925c 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -193,8 +193,7 @@ SwPaM* SwAccessibleParagraph::GetCursor( const bool _bForSelection )
     if ( pCursorShell != nullptr &&
          ( _bForSelection || !pCursorShell->IsTableMode() ) )
     {
-        SwFEShell *pFESh = dynamic_cast<const SwFEShell*>( pCursorShell) !=  nullptr
-                            ? static_cast< SwFEShell * >( pCursorShell ) : nullptr;
+        SwFEShell *pFESh = dynamic_cast<SwFEShell*>(pCursorShell);
         if( !pFESh ||
             !(pFESh->IsFrameSelected() || pFESh->IsObjSelected() > 0) )
         {
diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx
index 9f3770968228..6310be986709 100644
--- a/sw/source/core/doc/docfly.cxx
+++ b/sw/source/core/doc/docfly.cxx
@@ -754,9 +754,8 @@ bool SwDoc::ChgAnchor( const SdrMarkList& _rMrkList,
             if ( !pContact )
             {
 #if OSL_DEBUG_LEVEL > 0
-                bool bNoUserCallExcepted =
-                        dynamic_cast<const SwDrawVirtObj*>( pObj) !=  nullptr &&
-                        !static_cast<SwDrawVirtObj*>(pObj)->IsConnected();
+                auto pSwDrawVirtObj = dynamic_cast<SwDrawVirtObj*>( pObj);
+                bool bNoUserCallExcepted = pSwDrawVirtObj && !pSwDrawVirtObj->IsConnected();
                 OSL_ENSURE( bNoUserCallExcepted, "SwDoc::ChgAnchor(..) - no contact at selected drawing object" );
 #endif
                 continue;
@@ -943,8 +942,8 @@ bool SwDoc::ChgAnchor( const SdrMarkList& _rMrkList,
                 {
                     // #i33313# - consider not connected 'virtual' drawing
                     // objects
-                    if ( dynamic_cast<const SwDrawVirtObj*>( pObj) !=  nullptr &&
-                         !static_cast<SwDrawVirtObj*>(pObj)->IsConnected() )
+                    auto pSwDrawVirtObj = dynamic_cast<SwDrawVirtObj*>( pObj);
+                    if ( pSwDrawVirtObj && !pSwDrawVirtObj->IsConnected() )
                     {
                         SwRect aNewObjRect( aObjRect );
                         static_cast<SwAnchoredDrawObject*>(pContact->GetAnchoredObj( nullptr ))
diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx
index ba9641b3d42f..41b894b4afad 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -1085,14 +1085,14 @@ static void lcl_UpdateLinksInSect( SwBaseLink& rUpdLnk, SwSectionNode& rSectNd )
     const ::sfx2::SvBaseLinks& rLnks = rDoc.getIDocumentLinksAdministration().GetLinkManager().GetLinks();
     for( auto n = rLnks.size(); n; )
     {
-        SwBaseLink* pBLink;
-
         ::sfx2::SvBaseLink* pLnk = &(*rLnks[ --n ]);
-        if( pLnk != &rUpdLnk &&
-            sfx2::SvBaseLinkObjectType::ClientFile == pLnk->GetObjType() &&
-            dynamic_cast< const SwBaseLink *>( pLnk ) !=  nullptr &&
-            ( pBLink = static_cast<SwBaseLink*>(pLnk) )->IsInRange( rSectNd.GetIndex(),
-                                                rSectNd.EndOfSectionIndex() ) )
+        if( pLnk == &rUpdLnk )
+            continue;
+        if( sfx2::SvBaseLinkObjectType::ClientFile != pLnk->GetObjType() )
+            continue;
+        SwBaseLink* pBLink = dynamic_cast<SwBaseLink*>( pLnk );
+        if( pBLink && pBLink->IsInRange( rSectNd.GetIndex(),
+                                        rSectNd.EndOfSectionIndex() ) )
         {
             // It's in the Section, so update. But only if it's not in the same File!
             OUString sFName;
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index baf24ba82a96..e1c7eee5148e 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -701,9 +701,10 @@ SwFlyNotify::~SwFlyNotify()
     // OD 2004-05-13 #i28701#
     // #i45180# - no adjustment of layout process flags and
     // further notifications/invalidations, if format is called by grow/shrink
-    if ( !(pFly->ConsiderObjWrapInfluenceOnObjPos() &&
-         ( dynamic_cast<const SwFlyFreeFrame*>( pFly) ==  nullptr ||
-           !static_cast<SwFlyFreeFrame*>(pFly)->IsNoMoveOnCheckClip() )) )
+    if ( !pFly->ConsiderObjWrapInfluenceOnObjPos() )
+        return;
+    auto pFlyFreeFrame = dynamic_cast<SwFlyFreeFrame*>(pFly);
+    if (pFlyFreeFrame && pFlyFreeFrame->IsNoMoveOnCheckClip())
         return;
 
     // #i54138# - suppress restart of the layout process
diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index 45ac680c8f4f..249d63e15b6d 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -107,18 +107,18 @@ bool SwLayAction::PaintWithoutFlys( const SwRect &rRect, const SwContentFrame *p
 
     for ( size_t i = 0; i < rObjs.size() && !aTmp.empty(); ++i )
     {
-        SdrObject *pO = rObjs[i]->DrawObj();
-        if ( dynamic_cast< const SwVirtFlyDrawObj *>( pO ) ==  nullptr )
+        SwVirtFlyDrawObj *pVirtFly = dynamic_cast<SwVirtFlyDrawObj*>(rObjs[i]->DrawObj());
+        if ( !pVirtFly )
             continue;
 
         // do not consider invisible objects
         const IDocumentDrawModelAccess& rIDDMA = pPage->GetFormat()->getIDocumentDrawModelAccess();
-        if ( !rIDDMA.IsVisibleLayerId( pO->GetLayer() ) )
+        if ( !rIDDMA.IsVisibleLayerId( pVirtFly->GetLayer() ) )
         {
             continue;
         }
 
-        SwFlyFrame *pFly = static_cast<SwVirtFlyDrawObj*>(pO)->GetFlyFrame();
+        SwFlyFrame *pFly = pVirtFly->GetFlyFrame();
 
         if ( pFly == pSelfFly || !rRect.IsOver( pFly->getFrameArea() ) )
             continue;
@@ -132,9 +132,9 @@ bool SwLayAction::PaintWithoutFlys( const SwRect &rRect, const SwContentFrame *p
         if ( pSelfFly )
         {
             const SdrObject *pTmp = pSelfFly->GetVirtDrawObj();
-            if ( pO->GetLayer() == pTmp->GetLayer() )
+            if ( pVirtFly->GetLayer() == pTmp->GetLayer() )
             {
-                if ( pO->GetOrdNumDirect() < pTmp->GetOrdNumDirect() )
+                if ( pVirtFly->GetOrdNumDirect() < pTmp->GetOrdNumDirect() )
                     // Only look at things above us, if inside the same layer
                     continue;
             }
diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx
index a7bf0fbcb7b6..fca024db0e9a 100644
--- a/sw/source/core/text/txtftn.cxx
+++ b/sw/source/core/text/txtftn.cxx
@@ -240,8 +240,9 @@ static SwTwips lcl_GetFootnoteLower( const SwTextFrame* pFrame, SwTwips nLower )
             {
                 SwRect aRect( pAnchoredObj->GetObjRect() );
 
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) ==  nullptr ||
-                     static_cast<SwFlyFrame*>(pAnchoredObj)->isFrameAreaDefinitionValid() )
+                auto pFlyFrame = dynamic_cast<SwFlyFrame*>( pAnchoredObj );
+                if ( !pFlyFrame ||
+                     pFlyFrame->isFrameAreaDefinitionValid() )
                 {
                     const SwTwips nBottom = aRectFnSet.GetBottom(aRect);
                     if ( aRectFnSet.YDiff( nBottom, nFlyLower ) > 0 )
diff --git a/sw/source/uibase/uiview/viewdraw.cxx b/sw/source/uibase/uiview/viewdraw.cxx
index 766489bcf09c..f27000acbd71 100644
--- a/sw/source/uibase/uiview/viewdraw.cxx
+++ b/sw/source/uibase/uiview/viewdraw.cxx
@@ -473,17 +473,18 @@ bool SwView::EnterDrawTextMode(const Point& aDocPos)
     if (pSdrView->IsMarkedHit(aDocPos) && !pSdrView->PickHandle(aDocPos) && IsTextTool())
         pObj = pSdrView->PickObj(aDocPos, pSdrView->getHitTolLog(), pPV, SdrSearchOptions::PICKTEXTEDIT);
 
-    if (pObj &&
-        // To allow SwDrawVirtObj text objects to be activated, allow their type, too.
-        ( dynamic_cast< const SdrTextObj *>( pObj ) !=  nullptr ||
-          ( dynamic_cast< const SwDrawVirtObj *>( pObj ) !=  nullptr &&
-            dynamic_cast< const SdrTextObj *>(&static_cast<SwDrawVirtObj*>(pObj)->GetReferencedObj() ) != nullptr ) ) &&
-
-        m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content) == FlyProtectFlags::NONE)
+    if (pObj)
     {
-        // Refuse to edit editeng text of the shape if it has textbox attached.
-        if (!lcl_isTextBox(pObj))
-            bReturn = BeginTextEdit( pObj, pPV, m_pEditWin );
+        // To allow SwDrawVirtObj text objects to be activated, allow their type, too.
+        auto pVirtObj =  dynamic_cast<SwDrawVirtObj*>( pObj );
+        if ( (pVirtObj && dynamic_cast< const SdrTextObj *>(&pVirtObj->GetReferencedObj() ) != nullptr &&
+               m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content) == FlyProtectFlags::NONE) ||
+             dynamic_cast< const SdrTextObj *>( pObj ) != nullptr )
+        {
+            // Refuse to edit editeng text of the shape if it has textbox attached.
+            if (!lcl_isTextBox(pObj))
+                bReturn = BeginTextEdit( pObj, pPV, m_pEditWin );
+        }
     }
 
     pSdrView->SetHitTolerancePixel( nOld );
diff --git a/vcl/source/edit/textundo.cxx b/vcl/source/edit/textundo.cxx
index 284300e9ec10..e7c2fe1c76aa 100644
--- a/vcl/source/edit/textundo.cxx
+++ b/vcl/source/edit/textundo.cxx
@@ -273,10 +273,9 @@ void TextUndoInsertChars::Redo()
 
 bool TextUndoInsertChars::Merge( SfxUndoAction* pNextAction )
 {
-    if ( nullptr == dynamic_cast< const TextUndoInsertChars*>( pNextAction ) )
-        return false;
-
     TextUndoInsertChars* pNext = static_cast<TextUndoInsertChars*>(pNextAction);
+    if ( !pNext )
+        return false;
 
     if ( maTextPaM.GetPara() != pNext->maTextPaM.GetPara() )
         return false;


More information about the Libreoffice-commits mailing list