[Libreoffice-commits] core.git: compilerplugins/clang editeng/source framework/source sc/source sd/source sfx2/source solenv/CompilerTest_compilerplugins_clang.mk svx/source sw/source

Noel Grandin noel.grandin at collabora.co.uk
Thu Nov 9 06:32:04 UTC 2017


 compilerplugins/clang/simplifydynamiccast.cxx           |  116 ++++++++++++++++
 compilerplugins/clang/test/simplifydynamiccast.cxx      |   34 ++++
 editeng/source/editeng/impedit2.cxx                     |    4 
 editeng/source/editeng/impedit3.cxx                     |    4 
 framework/source/layoutmanager/toolbarlayoutmanager.cxx |    4 
 sc/source/ui/dbgui/validate.cxx                         |    4 
 sc/source/ui/drawfunc/fuins2.cxx                        |    8 -
 sc/source/ui/navipi/content.cxx                         |    4 
 sc/source/ui/navipi/scenwnd.cxx                         |    8 -
 sc/source/ui/view/viewfun2.cxx                          |    8 -
 sd/source/core/drawdoc2.cxx                             |    3 
 sd/source/ui/app/sdmod2.cxx                             |    4 
 sd/source/ui/app/tmplctrl.cxx                           |    4 
 sd/source/ui/func/fuconrec.cxx                          |   18 +-
 sd/source/ui/func/futext.cxx                            |    3 
 sd/source/ui/view/DocumentRenderer.cxx                  |    4 
 sd/source/ui/view/drviews8.cxx                          |    7 
 sd/source/ui/view/drviewsf.cxx                          |    8 -
 sd/source/ui/view/outlnvsh.cxx                          |    8 -
 sfx2/source/appl/appuno.cxx                             |    8 -
 sfx2/source/control/bindings.cxx                        |    4 
 sfx2/source/toolbox/tbxitem.cxx                         |    4 
 solenv/CompilerTest_compilerplugins_clang.mk            |    1 
 svx/source/customshapes/EnhancedCustomShape3d.cxx       |    4 
 svx/source/customshapes/EnhancedCustomShapeEngine.cxx   |    4 
 svx/source/engine3d/view3d.cxx                          |    8 -
 svx/source/stbctrls/pszctrl.cxx                         |   12 -
 svx/source/stbctrls/xmlsecctrl.cxx                      |    4 
 svx/source/stbctrls/zoomctrl.cxx                        |    7 
 svx/source/svdraw/svdpagv.cxx                           |    4 
 sw/source/core/access/acccell.cxx                       |    3 
 sw/source/core/access/accframebase.cxx                  |    3 
 sw/source/core/access/accmap.cxx                        |    6 
 sw/source/core/doc/docdraw.cxx                          |    4 
 sw/source/core/docnode/node.cxx                         |    8 -
 sw/source/core/draw/dcontact.cxx                        |    4 
 sw/source/core/draw/dview.cxx                           |    4 
 sw/source/core/frmedt/feshview.cxx                      |   13 -
 sw/source/core/layout/atrfrm.cxx                        |    8 -
 sw/source/core/layout/flowfrm.cxx                       |    3 
 sw/source/core/layout/flylay.cxx                        |    4 
 sw/source/core/layout/frmtool.cxx                       |    4 
 sw/source/core/layout/layact.cxx                        |   13 -
 sw/source/core/layout/paintfrm.cxx                      |    6 
 sw/source/core/layout/tabfrm.cxx                        |    4 
 sw/source/core/text/txtfly.cxx                          |    4 
 sw/source/core/unocore/unoframe.cxx                     |   11 -
 sw/source/uibase/app/apphdl.cxx                         |    4 
 sw/source/uibase/app/docsh.cxx                          |    4 
 49 files changed, 275 insertions(+), 148 deletions(-)

New commits:
commit 5ba447bdcd13ba3d7c27c8609f207910227e4ab6
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Nov 7 13:55:06 2017 +0200

    new loplugin simplifydynamiccast
    
    simplify dynamic_cast followed by static_cast
    
    Change-Id: I965afcf05d1675094cfde53d3590a0fd00f26279
    Reviewed-on: https://gerrit.libreoffice.org/44460
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/simplifydynamiccast.cxx b/compilerplugins/clang/simplifydynamiccast.cxx
new file mode 100644
index 000000000000..f305f8cbeaef
--- /dev/null
+++ b/compilerplugins/clang/simplifydynamiccast.cxx
@@ -0,0 +1,116 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cassert>
+#include <string>
+#include <iostream>
+#include <fstream>
+#include <set>
+
+#include <clang/AST/CXXInheritance.h>
+#include "compat.hxx"
+#include "plugin.hxx"
+
+namespace
+{
+class SimplifyDynamicCast : public RecursiveASTVisitor<SimplifyDynamicCast>, public loplugin::Plugin
+{
+public:
+    explicit SimplifyDynamicCast(loplugin::InstantiationData const& data)
+        : Plugin(data)
+    {
+    }
+
+    virtual void run() override
+    {
+        //        StringRef fn( compiler.getSourceManager().getFileEntryForID(
+        //                          compiler.getSourceManager().getMainFileID())->getName() );
+        //        if (loplugin::isSamePathname(fn, WORKDIR "/YaccTarget/unoidl/source/sourceprovider-parser.cxx"))
+        //             return;
+
+        TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
+    }
+
+    bool TraverseIfStmt(IfStmt*);
+    bool VisitCXXStaticCastExpr(CXXStaticCastExpr const*);
+
+private:
+    std::vector<QualType> dynamicCastVec;
+    std::vector<Decl const*> dynamicCastSubExprVec;
+    std::vector<IfStmt const*> ifVec;
+};
+
+bool SimplifyDynamicCast::TraverseIfStmt(IfStmt* ifStmt)
+{
+    auto condExpr = ifStmt->getCond()->IgnoreParenImpCasts();
+    auto dynamicCastExpr = dyn_cast<CXXDynamicCastExpr>(condExpr);
+    if (!dynamicCastExpr)
+    {
+        if (auto binaryOp = dyn_cast<BinaryOperator>(condExpr))
+        {
+            if (binaryOp->getOpcode() == BO_NE)
+                dynamicCastExpr
+                    = dyn_cast<CXXDynamicCastExpr>(binaryOp->getLHS()->IgnoreParenImpCasts());
+        }
+    }
+    Decl const* subExprDecl = nullptr;
+    if (dynamicCastExpr)
+    {
+        auto subExprDeclRefExpr
+            = dyn_cast<DeclRefExpr>(dynamicCastExpr->getSubExpr()->IgnoreParenImpCasts());
+        if (!subExprDeclRefExpr)
+            dynamicCastExpr = nullptr;
+        else
+            subExprDecl = subExprDeclRefExpr->getDecl();
+    }
+    if (dynamicCastExpr)
+    {
+        auto qt = dynamicCastExpr->getTypeAsWritten();
+        dynamicCastVec.push_back(qt);
+        dynamicCastSubExprVec.push_back(subExprDecl);
+        ifVec.push_back(ifStmt);
+    }
+    bool ret = RecursiveASTVisitor::TraverseIfStmt(ifStmt);
+    if (dynamicCastExpr)
+    {
+        dynamicCastVec.pop_back();
+        dynamicCastSubExprVec.pop_back();
+        ifVec.pop_back();
+    }
+    return ret;
+}
+
+bool SimplifyDynamicCast::VisitCXXStaticCastExpr(CXXStaticCastExpr const* staticCastExpr)
+{
+    if (ignoreLocation(staticCastExpr))
+        return true;
+    if (dynamicCastVec.empty())
+        return true;
+
+    auto qt = staticCastExpr->getTypeAsWritten();
+    auto it = std::find(dynamicCastVec.begin(), dynamicCastVec.end(), qt);
+    if (it == dynamicCastVec.end())
+        return true;
+    int idx = it - dynamicCastVec.begin();
+    auto subExprDecl = dyn_cast<DeclRefExpr>(staticCastExpr->getSubExpr()->IgnoreParenImpCasts());
+    if (!subExprDecl)
+        return true;
+    if (dynamicCastSubExprVec[idx] != subExprDecl->getDecl())
+        return true;
+    report(DiagnosticsEngine::Warning, "simplify, use var in if", staticCastExpr->getLocStart())
+        << staticCastExpr->getSourceRange();
+    auto ifStmt = ifVec[idx];
+    report(DiagnosticsEngine::Note, "if here", ifStmt->getLocStart()) << ifStmt->getSourceRange();
+    return true;
+}
+
+loplugin::Plugin::Registration<SimplifyDynamicCast> X("simplifydynamiccast", true);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/compilerplugins/clang/test/simplifydynamiccast.cxx b/compilerplugins/clang/test/simplifydynamiccast.cxx
new file mode 100644
index 000000000000..111734f0a511
--- /dev/null
+++ b/compilerplugins/clang/test/simplifydynamiccast.cxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+struct ClassA
+{
+    virtual ~ClassA() {}
+};
+
+struct ClassB : public ClassA
+{
+    void foo() {}
+};
+
+void f1(ClassA* p1)
+{
+    if (dynamic_cast<ClassB*>(p1)) // expected-note {{if here [loplugin:simplifydynamiccast]}}
+    {
+        static_cast<ClassB*>(p1)
+            ->foo(); // expected-error at -1 {{simplify, use var in if [loplugin:simplifydynamiccast]}}
+    }
+    if (dynamic_cast<ClassB*>(p1) != nullptr)
+    { // expected-note at -1 {{if here [loplugin:simplifydynamiccast]}}
+        static_cast<ClassB*>(p1)
+            ->foo(); // expected-error at -1 {{simplify, use var in if [loplugin:simplifydynamiccast]}}
+    }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx
index 2ba8c6cde892..ff2cd22249af 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -3496,10 +3496,10 @@ uno::Reference< datatransfer::XTransferable > ImpEditEngine::CreateTransferable(
         {
             const SvxFieldItem* pField = static_cast<const SvxFieldItem*>(pAttr->GetItem());
             const SvxFieldData* pFld = pField->GetField();
-            if ( dynamic_cast<const SvxURLField* >(pFld) !=  nullptr )
+            if ( auto pUrlField = dynamic_cast<const SvxURLField* >(pFld) )
             {
                 // Office-Bookmark
-                pDataObj->GetURL() = static_cast<const SvxURLField*>(pFld)->GetURL();
+                pDataObj->GetURL() = pUrlField->GetURL();
             }
         }
     }
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index ba56dce73a14..6d153502585f 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -3617,7 +3617,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
                                                 if( pFieldItem )
                                                 {
                                                     const SvxFieldData* pFieldData = pFieldItem->GetField();
-                                                    if ( dynamic_cast< const SvxURLField* >( pFieldData ) !=  nullptr)
+                                                    if ( auto pUrlField = dynamic_cast< const SvxURLField* >( pFieldData ) )
                                                     {
                                                         Point aTopLeft( aTmpPos );
                                                         aTopLeft.Y() -= pLine->GetMaxAscent();
@@ -3625,7 +3625,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
                                                         tools::Rectangle aRect( aTopLeft, rTextPortion.GetSize() );
                                                         vcl::PDFExtOutDevBookmarkEntry aBookmark;
                                                         aBookmark.nLinkId = pPDFExtOutDevData->CreateLink( aRect );
-                                                        aBookmark.aBookmark = static_cast<const SvxURLField*>(pFieldData)->GetURL();
+                                                        aBookmark.aBookmark = pUrlField->GetURL();
                                                         std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFExtOutDevData->GetBookmarks();
                                                         rBookmarks.push_back( aBookmark );
                                                     }
diff --git a/framework/source/layoutmanager/toolbarlayoutmanager.cxx b/framework/source/layoutmanager/toolbarlayoutmanager.cxx
index dd29eecba748..1e4612726dec 100644
--- a/framework/source/layoutmanager/toolbarlayoutmanager.cxx
+++ b/framework/source/layoutmanager/toolbarlayoutmanager.cxx
@@ -917,13 +917,13 @@ long ToolbarLayoutManager::childWindowEvent( VclSimpleEvent const * pEvent )
     // To enable toolbar controllers to change their image when a sub-toolbar function
     // is activated, we need this mechanism. We have NO connection between these toolbars
     // anymore!
-    if ( dynamic_cast< const VclWindowEvent* >(pEvent) != nullptr )
+    if ( auto pWindowEvent = dynamic_cast< const VclWindowEvent* >(pEvent) )
     {
         if ( pEvent->GetId() == VclEventId::ToolboxSelect )
         {
             OUString aToolbarName;
             OUString aCommand;
-            ToolBox*        pToolBox = getToolboxPtr( static_cast<VclWindowEvent const *>(pEvent)->GetWindow() );
+            ToolBox* pToolBox = getToolboxPtr( pWindowEvent->GetWindow() );
 
             if ( pToolBox )
             {
diff --git a/sc/source/ui/dbgui/validate.cxx b/sc/source/ui/dbgui/validate.cxx
index 6f4c08ebcaa5..d98e11e3eb6d 100644
--- a/sc/source/ui/dbgui/validate.cxx
+++ b/sc/source/ui/dbgui/validate.cxx
@@ -518,8 +518,8 @@ ScValidationDlg * ScTPValidationValue::GetValidationDlg()
 {
     if( vcl::Window *pParent = GetParent() )
         do{
-            if ( dynamic_cast<ScValidationDlg*>( pParent ) )
-                return static_cast< ScValidationDlg * >( pParent );
+            if ( auto pValidationDlg = dynamic_cast<ScValidationDlg*>( pParent ) )
+                return pValidationDlg;
         }while ( nullptr != ( pParent = pParent->GetParent() ) );
     return nullptr;
 }
diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx
index 15904ee521e6..08466129371d 100644
--- a/sc/source/ui/drawfunc/fuins2.cxx
+++ b/sc/source/ui/drawfunc/fuins2.cxx
@@ -530,14 +530,14 @@ FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawV
 
         if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
         {
-            if ( dynamic_cast<const SfxUInt16Item*>( pItem) !=  nullptr )
-                nToTable = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
-            else if ( dynamic_cast<const SfxBoolItem*>( pItem) !=  nullptr )
+            if ( auto pUInt16Item = dynamic_cast<const SfxUInt16Item*>( pItem) )
+                nToTable = pUInt16Item->GetValue();
+            else if ( auto pBoolItem = dynamic_cast<const SfxBoolItem*>( pItem) )
             {
                 //  In IDL for Basic FN_PARAM_4 means SfxBoolItem
                 //  -> if set new table, else current table
 
-                if ( static_cast<const SfxBoolItem*>(pItem)->GetValue() )
+                if ( pBoolItem->GetValue() )
                     nToTable = static_cast<sal_uInt16>(rScDoc.GetTableCount());
                 else
                     nToTable = static_cast<sal_uInt16>(rData.GetTabNo());
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx
index 7549bb6a51e4..4b14ddf3add9 100644
--- a/sc/source/ui/navipi/content.cxx
+++ b/sc/source/ui/navipi/content.cxx
@@ -1068,10 +1068,10 @@ const ScAreaLink* ScContentTree::GetLink( sal_uLong nIndex )
     for (sal_uInt16 i=0; i<nCount; i++)
     {
         ::sfx2::SvBaseLink* pBase = rLinks[i].get();
-        if (dynamic_cast<const ScAreaLink*>( pBase) !=  nullptr)
+        if (auto pAreaLink = dynamic_cast<const ScAreaLink*>( pBase))
         {
             if (nFound == nIndex)
-                return static_cast<const ScAreaLink*>(pBase);
+                return pAreaLink;
             ++nFound;
         }
     }
diff --git a/sc/source/ui/navipi/scenwnd.cxx b/sc/source/ui/navipi/scenwnd.cxx
index 6b65715124bc..9038acb74664 100644
--- a/sc/source/ui/navipi/scenwnd.cxx
+++ b/sc/source/ui/navipi/scenwnd.cxx
@@ -247,18 +247,18 @@ void ScScenarioWindow::NotifyState( const SfxPoolItem* pState )
     {
         aLbScenario->Enable();
 
-        if ( dynamic_cast<const SfxStringItem*>( pState) !=  nullptr )
+        if ( auto pStringItem = dynamic_cast<const SfxStringItem*>( pState) )
         {
-            OUString aNewEntry( static_cast<const SfxStringItem*>(pState)->GetValue() );
+            OUString aNewEntry( pStringItem->GetValue() );
 
             if ( !aNewEntry.isEmpty() )
                 aLbScenario->SelectEntry( aNewEntry );
             else
                 aLbScenario->SetNoSelection();
         }
-        else if ( dynamic_cast<const SfxStringListItem*>( pState) !=  nullptr )
+        else if ( auto pStringListItem = dynamic_cast<const SfxStringListItem*>( pState) )
         {
-            aLbScenario->UpdateEntries( static_cast<const SfxStringListItem*>(pState)->GetList() );
+            aLbScenario->UpdateEntries( pStringListItem->GetList() );
         }
     }
     else
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 1a8e08520db4..fb4c178e10f1 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2616,11 +2616,11 @@ void ScViewFunc::MoveTable(
                     { &aItem, &aTarget });
         if ( pRetItem )
         {
-            if ( dynamic_cast<const SfxObjectItem*>( pRetItem) !=  nullptr )
-                pDestShell = dynamic_cast<ScDocShell*>( static_cast<const SfxObjectItem*>(pRetItem)->GetShell()  );
-            else if ( dynamic_cast<const SfxViewFrameItem*>( pRetItem) !=  nullptr )
+            if ( auto pObjectItem = dynamic_cast<const SfxObjectItem*>(pRetItem) )
+                pDestShell = dynamic_cast<ScDocShell*>( pObjectItem->GetShell()  );
+            else if ( auto pViewFrameItem = dynamic_cast<const SfxViewFrameItem*>( pRetItem) )
             {
-                SfxViewFrame* pFrm = static_cast<const SfxViewFrameItem*>(pRetItem)->GetFrame();
+                SfxViewFrame* pFrm = pViewFrameItem->GetFrame();
                 if (pFrm)
                     pDestShell = dynamic_cast<ScDocShell*>( pFrm->GetObjectShell()  );
             }
diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx
index 3b1621799302..4862d47e7dd9 100644
--- a/sd/source/core/drawdoc2.cxx
+++ b/sd/source/core/drawdoc2.cxx
@@ -1046,9 +1046,8 @@ IMapObject* SdDrawDocument::GetHitIMapObject( SdrObject const * pObj,
         bool                bObjSupported = false;
 
         // execute HitTest
-        if ( dynamic_cast< const SdrGrafObj *>( pObj ) !=  nullptr  ) // simple graphics object
+        if ( auto pGrafObj = dynamic_cast< const SdrGrafObj *>( pObj ) ) // simple graphics object
         {
-            const SdrGrafObj*   pGrafObj = static_cast<const SdrGrafObj*>(pObj);
             const GeoStat&      rGeo = pGrafObj->GetGeoStat();
             SdrGrafObjGeoData*  pGeoData = static_cast<SdrGrafObjGeoData*>( pGrafObj->GetGeoData() );
 
diff --git a/sd/source/ui/app/sdmod2.cxx b/sd/source/ui/app/sdmod2.cxx
index b7b51f41917c..9fc37b1c70e4 100644
--- a/sd/source/ui/app/sdmod2.cxx
+++ b/sd/source/ui/app/sdmod2.cxx
@@ -91,8 +91,8 @@ static SdPage* GetCurrentPage( sd::ViewShell const * pViewSh, EditFieldInfo cons
 
     // first try to check if we are inside the outline view
     sd::OutlineView* pSdView = nullptr;
-    if( dynamic_cast<const sd::OutlineViewShell* >(pViewSh) !=  nullptr )
-        pSdView = static_cast<sd::OutlineView*> (static_cast<sd::OutlineViewShell const *>(pViewSh)->GetView());
+    if( auto pOutlineViewShell = dynamic_cast<const sd::OutlineViewShell* >(pViewSh) )
+        pSdView = static_cast<sd::OutlineView*>(pOutlineViewShell->GetView());
 
     if (pSdView != nullptr && (pOutliner ==  &pSdView->GetOutliner()))
     {
diff --git a/sd/source/ui/app/tmplctrl.cxx b/sd/source/ui/app/tmplctrl.cxx
index 689dde24db77..a90e0a7bf535 100644
--- a/sd/source/ui/app/tmplctrl.cxx
+++ b/sd/source/ui/app/tmplctrl.cxx
@@ -78,9 +78,9 @@ void SdTemplateControl::StateChanged(
 {
     if( eState != SfxItemState::DEFAULT || pState->IsVoidItem() )
         GetStatusBar().SetItemText( GetId(), OUString() );
-    else if ( dynamic_cast< const SfxStringItem *>( pState ) !=  nullptr )
+    else if ( auto pStringItem = dynamic_cast< const SfxStringItem *>( pState ) )
     {
-        msTemplate = static_cast<const SfxStringItem*>(pState)->GetValue();
+        msTemplate = pStringItem->GetValue();
         GetStatusBar().SetItemText( GetId(), msTemplate );
     }
 }
diff --git a/sd/source/ui/func/fuconrec.cxx b/sd/source/ui/func/fuconrec.cxx
index bc5f9c5685c5..e10b37b53c0e 100644
--- a/sd/source/ui/func/fuconrec.cxx
+++ b/sd/source/ui/func/fuconrec.cxx
@@ -819,11 +819,11 @@ SdrObject* FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const
 
             case SID_DRAW_MEASURELINE:
             {
-                if( dynamic_cast< SdrMeasureObj *>( pObj ) !=  nullptr)
+                if( auto pMeasureObj = dynamic_cast< SdrMeasureObj *>( pObj ) )
                 {
                     sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
-                    static_cast<SdrMeasureObj*>(pObj)->SetPoint(Point(aStart.X(), nYMiddle), 0);
-                    static_cast<SdrMeasureObj*>(pObj)->SetPoint(Point(aEnd.X(), nYMiddle), 1);
+                    pMeasureObj->SetPoint(Point(aStart.X(), nYMiddle), 0);
+                    pMeasureObj->SetPoint(Point(aEnd.X(), nYMiddle), 1);
                 }
                 else
                 {
@@ -862,10 +862,10 @@ SdrObject* FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const
             case SID_CONNECTOR_LINES_CIRCLE_END:
             case SID_CONNECTOR_LINES_CIRCLES:
             {
-                if( dynamic_cast< SdrEdgeObj *>( pObj ) !=  nullptr)
+                if( auto pEdgeObj = dynamic_cast< SdrEdgeObj *>( pObj ) )
                 {
-                    static_cast<SdrEdgeObj*>(pObj)->SetTailPoint(false, aStart);
-                    static_cast<SdrEdgeObj*>(pObj)->SetTailPoint(true, aEnd);
+                    pEdgeObj->SetTailPoint(false, aStart);
+                    pEdgeObj->SetTailPoint(true, aEnd);
                 }
                 else
                 {
@@ -877,7 +877,7 @@ SdrObject* FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const
             case SID_DRAW_CAPTION:
             case SID_DRAW_CAPTION_VERTICAL:
             {
-                if( dynamic_cast< SdrCaptionObj *>( pObj ) !=  nullptr)
+                if( auto pCaptionObj = dynamic_cast< SdrCaptionObj *>( pObj ) )
                 {
                     bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
 
@@ -893,8 +893,8 @@ SdrObject* FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const
 
                     // The default text is not inserted anymore.
 
-                    static_cast<SdrCaptionObj*>(pObj)->SetLogicRect(aRect);
-                    static_cast<SdrCaptionObj*>(pObj)->SetTailPos(
+                    pCaptionObj->SetLogicRect(aRect);
+                    pCaptionObj->SetTailPos(
                         aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
                 }
                 else
diff --git a/sd/source/ui/func/futext.cxx b/sd/source/ui/func/futext.cxx
index 9ea0570e6e17..2b4ca65526cb 100644
--- a/sd/source/ui/func/futext.cxx
+++ b/sd/source/ui/func/futext.cxx
@@ -1313,9 +1313,8 @@ SdrObject* FuText::CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rect
 
     if(pObj)
     {
-        if( dynamic_cast< SdrTextObj *>( pObj ) !=  nullptr)
+        if( auto pText = dynamic_cast< SdrTextObj *>( pObj ) )
         {
-            SdrTextObj* pText = static_cast<SdrTextObj*>(pObj);
             pText->SetLogicRect(rRectangle);
 
             bool bVertical = (SID_ATTR_CHAR_VERTICAL == nID || SID_TEXT_FITTOSIZE_VERTICAL == nID);
diff --git a/sd/source/ui/view/DocumentRenderer.cxx b/sd/source/ui/view/DocumentRenderer.cxx
index 608a4af642bb..426f06615983 100644
--- a/sd/source/ui/view/DocumentRenderer.cxx
+++ b/sd/source/ui/view/DocumentRenderer.cxx
@@ -1414,8 +1414,8 @@ private:
             rOutliner.SetControlWord( nCntrl );
 
             // When in outline view then apply all pending changes to the model.
-            if( dynamic_cast< OutlineViewShell *>( pShell ) !=  nullptr)
-                static_cast<OutlineViewShell*>(pShell)->PrepareClose (false);
+            if( auto pOutlineViewShell = dynamic_cast< OutlineViewShell *>( pShell ) )
+                pOutlineViewShell->PrepareClose (false);
 
             // Collect some frequently used data.
             if (mpOptions->IsDate())
diff --git a/sd/source/ui/view/drviews8.cxx b/sd/source/ui/view/drviews8.cxx
index 29e6cb2ab683..3d0bf89a5888 100644
--- a/sd/source/ui/view/drviews8.cxx
+++ b/sd/source/ui/view/drviews8.cxx
@@ -97,7 +97,6 @@ void DrawViewShell::ScannerEvent()
                     Point aPnt ( ( aPageSize.Width() - aBmpSize.Width() ) >> 1, ( aPageSize.Height() - aBmpSize.Height() ) >> 1 );
                     aPnt += Point( pPage->GetLeftBorder(), pPage->GetUpperBorder() );
                     ::tools::Rectangle   aRect( aPnt, aBmpSize );
-                    SdrGrafObj* pGrafObj = nullptr;
                     bool        bInsertNewObject = true;
 
                     if( GetView()->AreObjectsMarked() )
@@ -109,10 +108,8 @@ void DrawViewShell::ScannerEvent()
                             SdrMark*    pMark = rMarkList.GetMark(0);
                             SdrObject*  pObj = pMark->GetMarkedSdrObj();
 
-                            if( dynamic_cast< SdrGrafObj *>( pObj ) !=  nullptr )
+                            if( auto pGrafObj = dynamic_cast< SdrGrafObj *>( pObj ) )
                             {
-                                pGrafObj = static_cast< SdrGrafObj* >( pObj );
-
                                 if( pGrafObj->IsEmptyPresObj() )
                                 {
                                     bInsertNewObject = false;
@@ -126,7 +123,7 @@ void DrawViewShell::ScannerEvent()
 
                     if( bInsertNewObject )
                     {
-                        pGrafObj = new SdrGrafObj( Graphic( aScanBmp ), aRect );
+                        auto pGrafObj = new SdrGrafObj( Graphic( aScanBmp ), aRect );
                         SdrPageView* pPV = GetView()->GetSdrPageView();
                         GetView()->InsertObjectAtView( pGrafObj, *pPV, SdrInsertFlags::SETDEFLAYER );
                     }
diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx
index 28210ef42cb2..218312476031 100644
--- a/sd/source/ui/view/drviewsf.cxx
+++ b/sd/source/ui/view/drviewsf.cxx
@@ -96,11 +96,11 @@ void DrawViewShell::GetCtrlState(SfxItemSet &rSet)
                 if ( abs( aSel.nEndPos - aSel.nStartPos ) == 1 )
                 {
                     const SvxFieldData* pField = pFieldItem->GetField();
-                    if( dynamic_cast< const SvxURLField *>( pField ) !=  nullptr)
+                    if( auto pUrlField = dynamic_cast< const SvxURLField *>( pField ) )
                     {
-                        aHLinkItem.SetName(static_cast<const SvxURLField*>(pField)->GetRepresentation());
-                        aHLinkItem.SetURL(static_cast<const SvxURLField*>(pField)->GetURL());
-                        aHLinkItem.SetTargetFrame(static_cast<const SvxURLField*>(pField)->GetTargetFrame());
+                        aHLinkItem.SetName(pUrlField->GetRepresentation());
+                        aHLinkItem.SetURL(pUrlField->GetURL());
+                        aHLinkItem.SetTargetFrame(pUrlField->GetTargetFrame());
                         bField = true;
                     }
                 }
diff --git a/sd/source/ui/view/outlnvsh.cxx b/sd/source/ui/view/outlnvsh.cxx
index 842ad38be060..6b53701739b8 100644
--- a/sd/source/ui/view/outlnvsh.cxx
+++ b/sd/source/ui/view/outlnvsh.cxx
@@ -362,11 +362,11 @@ void OutlineViewShell::GetCtrlState(SfxItemSet &rSet)
                 if ( abs( aSel.nEndPos - aSel.nStartPos ) == 1 )
                 {
                     const SvxFieldData* pField = pFieldItem->GetField();
-                    if ( dynamic_cast< const SvxURLField *>( pField ) !=  nullptr )
+                    if ( auto pUrlField = dynamic_cast< const SvxURLField *>( pField ) )
                     {
-                        aHLinkItem.SetName(static_cast<const SvxURLField*>(pField)->GetRepresentation());
-                        aHLinkItem.SetURL(static_cast<const SvxURLField*>(pField)->GetURL());
-                        aHLinkItem.SetTargetFrame(static_cast<const SvxURLField*>(pField)->GetTargetFrame());
+                        aHLinkItem.SetName(pUrlField->GetRepresentation());
+                        aHLinkItem.SetURL(pUrlField->GetURL());
+                        aHLinkItem.SetTargetFrame(pUrlField->GetTargetFrame());
                     }
                 }
             }
diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx
index 56ad256aa335..ca9ca3a13794 100644
--- a/sfx2/source/appl/appuno.cxx
+++ b/sfx2/source/appl/appuno.cxx
@@ -1400,13 +1400,13 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b
         if ( rSet.GetItemState( SID_FILLFRAME, false, &pItem ) == SfxItemState::SET )
         {
             pValue[nActProp].Name = sFrame;
-            if ( dynamic_cast< const SfxUsrAnyItem *>( pItem ) !=  nullptr )
+            if ( auto pUsrAnyItem = dynamic_cast< const SfxUsrAnyItem *>( pItem ) )
             {
                 OSL_FAIL( "TransformItems: transporting an XFrame via an SfxUsrAnyItem is not deprecated!" );
-                pValue[nActProp++].Value = static_cast< const SfxUsrAnyItem* >( pItem )->GetValue();
+                pValue[nActProp++].Value = pUsrAnyItem->GetValue();
             }
-            else if ( dynamic_cast< const SfxUnoFrameItem *>( pItem ) !=  nullptr )
-                pValue[nActProp++].Value <<= static_cast< const SfxUnoFrameItem* >( pItem )->GetFrame();
+            else if ( auto pUnoFrameItem = dynamic_cast< const SfxUnoFrameItem *>( pItem ) )
+                pValue[nActProp++].Value <<= pUnoFrameItem->GetFrame();
             else
                 OSL_FAIL( "TransformItems: invalid item type for SID_FILLFRAME!" );
         }
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index a71060120efd..1356c20fc231 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -1019,10 +1019,10 @@ void SfxBindings::Execute_Impl( SfxRequest& aReq, const SfxSlot* pSlot, SfxShell
                    SfxItemPool::IsWhich(nWhich) &&
                    pOldItem ) )
             {
-                if ( dynamic_cast< const SfxBoolItem *>( pOldItem ) !=  nullptr )
+                if ( auto pOldBoolItem = dynamic_cast< const SfxBoolItem *>( pOldItem ) )
                 {
                     // we can toggle Bools
-                    bool bOldValue = static_cast<const SfxBoolItem *>(pOldItem)->GetValue();
+                    bool bOldValue = pOldBoolItem->GetValue();
                     SfxBoolItem *pNewItem = static_cast<SfxBoolItem*>(pOldItem->Clone());
                     pNewItem->SetValue( !bOldValue );
                     aReq.AppendItem( *pNewItem );
diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx
index ac06a2f659e4..4732b6bae239 100644
--- a/sfx2/source/toolbox/tbxitem.cxx
+++ b/sfx2/source/toolbox/tbxitem.cxx
@@ -619,10 +619,10 @@ void SfxToolBoxControl::StateChanged
         case SfxItemState::DEFAULT:
         if ( pState )
         {
-            if ( dynamic_cast< const SfxBoolItem* >(pState) !=  nullptr )
+            if ( auto pBoolItem = dynamic_cast< const SfxBoolItem* >(pState) )
             {
                 // BoolItem for checking
-                if ( static_cast<const SfxBoolItem*>(pState)->GetValue() )
+                if ( pBoolItem->GetValue() )
                     eTri = TRISTATE_TRUE;
                 nItemBits |= ToolBoxItemBits::CHECKABLE;
             }
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
index d68caf0b0720..a07c3fa2f9be 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -39,6 +39,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
     compilerplugins/clang/test/refcounting \
     compilerplugins/clang/test/salbool \
     compilerplugins/clang/test/salunicodeliteral \
+    compilerplugins/clang/test/simplifydynamiccast \
     compilerplugins/clang/test/stringconstant \
     compilerplugins/clang/test/unnecessarycatchthrow \
     compilerplugins/clang/test/unnecessaryoverride \
diff --git a/svx/source/customshapes/EnhancedCustomShape3d.cxx b/svx/source/customshapes/EnhancedCustomShape3d.cxx
index 6d65bcc0ff63..9a048049c370 100644
--- a/svx/source/customshapes/EnhancedCustomShape3d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape3d.cxx
@@ -377,7 +377,7 @@ SdrObject* EnhancedCustomShape3d::Create3DObject( const SdrObject* pShape2d, con
             SfxItemSet aLocalSet(aSet);
             drawing::FillStyle aLocalFillStyle(eFillStyle);
 
-            if ( dynamic_cast<const SdrPathObj*>( pNext) !=  nullptr )
+            if ( auto pPathObj = dynamic_cast<const SdrPathObj*>(pNext) )
             {
                 const SfxItemSet& rSet = pNext->GetMergedItemSet();
                 bool bNeedToConvertToContour(false);
@@ -453,7 +453,7 @@ SdrObject* EnhancedCustomShape3d::Create3DObject( const SdrObject* pShape2d, con
                 }
                 else
                 {
-                    aPolyPoly = static_cast<const SdrPathObj*>(pNext)->GetPathPoly();
+                    aPolyPoly = pPathObj->GetPathPoly();
                 }
             }
             else
diff --git a/svx/source/customshapes/EnhancedCustomShapeEngine.cxx b/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
index d4a6fc657fea..00100d8afad9 100644
--- a/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
@@ -415,9 +415,9 @@ drawing::PolyPolygonBezierCoords SAL_CALL EnhancedCustomShapeEngine::getLineGeom
                 basegfx::B2DPolyPolygon aPP;
                 const SdrObject* pNext = aIter.Next();
 
-                if ( dynamic_cast<const SdrPathObj*>( pNext) !=  nullptr )
+                if ( auto pPathObj = dynamic_cast<const SdrPathObj*>(pNext) )
                 {
-                    aPP = static_cast<const SdrPathObj*>(pNext)->GetPathPoly();
+                    aPP = pPathObj->GetPathPoly();
                 }
                 else
                 {
diff --git a/svx/source/engine3d/view3d.cxx b/svx/source/engine3d/view3d.cxx
index d7edf4da5655..dd4396c91a56 100644
--- a/svx/source/engine3d/view3d.cxx
+++ b/svx/source/engine3d/view3d.cxx
@@ -418,9 +418,9 @@ SdrModel* E3dView::GetMarkedObjModel() const
             {
                 const SdrObject* pSrcOb=pSrcPg->GetObj(nOb);
 
-                if(dynamic_cast< const E3dScene* >( pSrcOb) !=  nullptr)
+                if(auto p3dscene = dynamic_cast< const E3dScene* >( pSrcOb))
                 {
-                    pScene = const_cast<E3dScene*>(static_cast<const E3dScene*>(pSrcOb));
+                    pScene = const_cast<E3dScene*>(p3dscene);
 
                     // delete all not intentionally cloned 3d objects
                     pScene->removeAllNonSelectedObjects();
@@ -476,9 +476,9 @@ bool E3dView::Paste(
             for(size_t nOb = 0; nOb < nObjCount; ++nOb)
             {
                 const SdrObject* pSrcOb = pSrcPg->GetObj(nOb);
-                if(dynamic_cast< const E3dScene* >(pSrcOb) !=  nullptr)
+                if(auto p3dscene = dynamic_cast< const E3dScene* >(pSrcOb))
                 {
-                    E3dScene* pSrcScene = const_cast<E3dScene*>(static_cast<const E3dScene*>(pSrcOb));
+                    E3dScene* pSrcScene = const_cast<E3dScene*>(p3dscene);
                     ImpCloneAll3DObjectsToDestScene(pSrcScene, pDstScene, aDist);
                 }
             }
diff --git a/svx/source/stbctrls/pszctrl.cxx b/svx/source/stbctrls/pszctrl.cxx
index 1ad57366f88a..334670aabb11 100644
--- a/svx/source/stbctrls/pszctrl.cxx
+++ b/svx/source/stbctrls/pszctrl.cxx
@@ -299,24 +299,24 @@ void SvxPosSizeStatusBarControl::StateChanged( sal_uInt16 nSID, SfxItemState eSt
             SAL_WARN( "svx.stbcrtls","unknown slot id");
         }
     }
-    else if ( dynamic_cast<const SfxPointItem*>( pState) !=  nullptr )
+    else if ( auto pPointItem = dynamic_cast<const SfxPointItem*>( pState) )
     {
         // show position
-        pImpl->aPos = static_cast<const SfxPointItem*>(pState)->GetValue();
+        pImpl->aPos = pPointItem->GetValue();
         pImpl->bPos = true;
         pImpl->bTable = false;
     }
-    else if ( dynamic_cast<const SvxSizeItem*>( pState) !=  nullptr )
+    else if ( auto pSizeItem = dynamic_cast<const SvxSizeItem*>( pState) )
     {
         // show size
-        pImpl->aSize = static_cast<const SvxSizeItem*>(pState)->GetSize();
+        pImpl->aSize = pSizeItem->GetSize();
         pImpl->bSize = true;
         pImpl->bTable = false;
     }
-    else if ( dynamic_cast<const SfxStringItem*>( pState) !=  nullptr )
+    else if ( auto pStringItem = dynamic_cast<const SfxStringItem*>( pState) )
     {
         // show string (table cel or different)
-        pImpl->aStr = static_cast<const SfxStringItem*>(pState)->GetValue();
+        pImpl->aStr = pStringItem->GetValue();
         pImpl->bTable = true;
         pImpl->bPos = false;
         pImpl->bSize = false;
diff --git a/svx/source/stbctrls/xmlsecctrl.cxx b/svx/source/stbctrls/xmlsecctrl.cxx
index 90e8b55fbe36..ae43e64dc405 100644
--- a/svx/source/stbctrls/xmlsecctrl.cxx
+++ b/svx/source/stbctrls/xmlsecctrl.cxx
@@ -71,9 +71,9 @@ void XmlSecStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState, cons
     {
         mpImpl->mnState = SignatureState::UNKNOWN;
     }
-    else if( dynamic_cast< const SfxUInt16Item* >(pState) !=  nullptr )
+    else if( auto pUint16Item = dynamic_cast< const SfxUInt16Item* >(pState) )
     {
-        mpImpl->mnState = static_cast<SignatureState>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
+        mpImpl->mnState = static_cast<SignatureState>(pUint16Item->GetValue());
     }
     else
     {
diff --git a/svx/source/stbctrls/zoomctrl.cxx b/svx/source/stbctrls/zoomctrl.cxx
index cf9b42cbc833..ed92af23be34 100644
--- a/svx/source/stbctrls/zoomctrl.cxx
+++ b/svx/source/stbctrls/zoomctrl.cxx
@@ -116,17 +116,16 @@ void SvxZoomStatusBarControl::StateChanged( sal_uInt16, SfxItemState eState,
         GetStatusBar().SetItemText( GetId(), "" );
         nValueSet = SvxZoomEnableFlags::NONE;
     }
-    else if ( dynamic_cast< const SfxUInt16Item* >(pState) !=  nullptr )
+    else if ( auto pItem = dynamic_cast< const SfxUInt16Item* >(pState) )
     {
-        const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
         nZoom = pItem->GetValue();
 
         OUString aStr(unicode::formatPercent(nZoom, Application::GetSettings().GetUILanguageTag()));
         GetStatusBar().SetItemText( GetId(), aStr );
 
-        if ( dynamic_cast<const SvxZoomItem*>( pState) !=  nullptr )
+        if ( auto pZoomItem = dynamic_cast<const SvxZoomItem*>(pState) )
         {
-            nValueSet = static_cast<const SvxZoomItem*>(pState)->GetValueSet();
+            nValueSet = pZoomItem->GetValueSet();
         }
         else
         {
diff --git a/svx/source/svdraw/svdpagv.cxx b/svx/source/svdraw/svdpagv.cxx
index 5f502bf1ed0d..ab837a7c58e6 100644
--- a/svx/source/svdraw/svdpagv.cxx
+++ b/svx/source/svdraw/svdpagv.cxx
@@ -642,11 +642,11 @@ bool SdrPageView::IsObjMarkable(SdrObject const * pObj) const
         return false;    // only visible are selectable
     if (!pObj->IsInserted())
         return false;    // Obj deleted?
-    if (dynamic_cast<const SdrObjGroup*>(pObj) !=  nullptr)
+    if (auto pObjGroup = dynamic_cast<const SdrObjGroup*>(pObj))
     {
         // If object is a Group object, visibility may depend on
         // multiple layers. If one object is markable, Group is markable.
-        SdrObjList* pObjList = static_cast<SdrObjGroup const *>(pObj)->GetSubList();
+        SdrObjList* pObjList = pObjGroup->GetSubList();
 
         if (pObjList && pObjList->GetObjCount())
         {
diff --git a/sw/source/core/access/acccell.cxx b/sw/source/core/access/acccell.cxx
index 7e344f78ef14..be8f61a891d3 100644
--- a/sw/source/core/access/acccell.cxx
+++ b/sw/source/core/access/acccell.cxx
@@ -59,9 +59,8 @@ bool SwAccessibleCell::IsSelected()
     assert(GetMap());
     const SwViewShell *pVSh = GetMap()->GetShell();
     assert(pVSh);
-    if( dynamic_cast<const SwCursorShell*>( pVSh) !=  nullptr )
+    if( auto pCSh = dynamic_cast<const SwCursorShell*>(pVSh) )
     {
-        const SwCursorShell *pCSh = static_cast< const SwCursorShell * >( pVSh );
         if( pCSh->IsTableMode() )
         {
             const SwCellFrame *pCFrame =
diff --git a/sw/source/core/access/accframebase.cxx b/sw/source/core/access/accframebase.cxx
index 7ca7d96aa934..221304bc3857 100644
--- a/sw/source/core/access/accframebase.cxx
+++ b/sw/source/core/access/accframebase.cxx
@@ -50,9 +50,8 @@ bool SwAccessibleFrameBase::IsSelected()
     assert(GetMap());
     const SwViewShell *pVSh = GetMap()->GetShell();
     assert(pVSh);
-    if( dynamic_cast<const SwFEShell*>( pVSh) !=  nullptr )
+    if( auto pFESh = dynamic_cast<const SwFEShell*>(pVSh) )
     {
-        const SwFEShell *pFESh = static_cast< const SwFEShell * >( pVSh );
         const SwFrame *pFlyFrame = pFESh->GetSelectedFlyFrame();
         if( pFlyFrame == GetFrame() )
             bRet = true;
diff --git a/sw/source/core/access/accmap.cxx b/sw/source/core/access/accmap.cxx
index cb065f10577d..66a022d49356 100644
--- a/sw/source/core/access/accmap.cxx
+++ b/sw/source/core/access/accmap.cxx
@@ -2507,17 +2507,15 @@ void SwAccessibleMap::InvalidateCursorPosition( const SwFrame *pFrame )
     SwAccessibleChild aFrameOrObj( pFrame );
     bool bShapeSelected = false;
     const SwViewShell *pVSh = GetShell();
-    if( dynamic_cast<const SwCursorShell*>( pVSh) !=  nullptr )
+    if( auto pCSh = dynamic_cast<const SwCursorShell*>(pVSh) )
     {
-        const SwCursorShell *pCSh = static_cast< const SwCursorShell * >( pVSh );
         if( pCSh->IsTableMode() )
         {
             while( aFrameOrObj.GetSwFrame() && !aFrameOrObj.GetSwFrame()->IsCellFrame() )
                 aFrameOrObj = aFrameOrObj.GetSwFrame()->GetUpper();
         }
-        else if( dynamic_cast<const SwFEShell*>( pVSh) !=  nullptr )
+        else if( auto pFESh = dynamic_cast<const SwFEShell*>(pVSh) )
         {
-            const SwFEShell *pFESh = static_cast< const SwFEShell * >( pVSh );
             const SwFrame *pFlyFrame = pFESh->GetSelectedFlyFrame();
             if( pFlyFrame )
             {
diff --git a/sw/source/core/doc/docdraw.cxx b/sw/source/core/doc/docdraw.cxx
index d57ce3cd6fa1..a7f68a62f30c 100644
--- a/sw/source/core/doc/docdraw.cxx
+++ b/sw/source/core/doc/docdraw.cxx
@@ -185,10 +185,8 @@ static void lcl_AdjustPositioningAttr( SwDrawFrameFormat* _pFrameFormat,
     // to adjust the positioning attributes - see <SwDrawContact::Changed_(..)>.
     {
         const SwAnchoredObject* pAnchoredObj = pContact->GetAnchoredObj( &_rSdrObj );
-        if ( dynamic_cast<const SwAnchoredDrawObject*>( pAnchoredObj) !=  nullptr )
+        if ( auto pAnchoredDrawObj = dynamic_cast<const SwAnchoredDrawObject*>( pAnchoredObj) )
         {
-            const SwAnchoredDrawObject* pAnchoredDrawObj =
-                            static_cast<const SwAnchoredDrawObject*>(pAnchoredObj);
             const SwRect aObjRect = _rSdrObj.GetSnapRect();
             const_cast<SwAnchoredDrawObject*>(pAnchoredDrawObj)
                                         ->SetLastObjRect( aObjRect.SVRect() );
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index 85052d36338e..5e242f388a83 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -674,10 +674,10 @@ const SwPageDesc* SwNode::FindPageDesc( size_t* pPgDescNdIdx ) const
                     static_cast<const SwFormatPageDesc*>(pItem)->GetDefinedIn() )
                 {
                     const SwModify* pMod = static_cast<const SwFormatPageDesc*>(pItem)->GetDefinedIn();
-                    if( dynamic_cast<const SwContentNode*>( pMod) !=  nullptr )
-                        aInfo.CheckNode( *static_cast<const SwContentNode*>(pMod) );
-                    else if( dynamic_cast<const SwFormat*>( pMod) !=  nullptr)
-                        static_cast<const SwFormat*>(pMod)->GetInfo( aInfo );
+                    if( auto pContentNode = dynamic_cast<const SwContentNode*>( pMod) )
+                        aInfo.CheckNode( *pContentNode );
+                    else if( auto pFormat = dynamic_cast<const SwFormat*>( pMod) )
+                        pFormat->GetInfo( aInfo );
                 }
             }
 
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index b0ef8d2a0600..2cc3235b8846 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -754,9 +754,9 @@ const SwAnchoredObject* SwDrawContact::GetAnchoredObj(const SdrObject* pSdrObj )
 
     const SwAnchoredObject* pRetAnchoredObj = nullptr;
 
-    if (dynamic_cast<const SwDrawVirtObj*>(pSdrObj) != nullptr)
+    if (auto pVirtObj = dynamic_cast<const SwDrawVirtObj*>(pSdrObj))
     {
-        pRetAnchoredObj = &(static_cast<const SwDrawVirtObj*>(pSdrObj)->GetAnchoredObj());
+        pRetAnchoredObj = &(pVirtObj->GetAnchoredObj());
     }
     else
     {
diff --git a/sw/source/core/draw/dview.cxx b/sw/source/core/draw/dview.cxx
index a728ba56d4b7..e34e167822e9 100644
--- a/sw/source/core/draw/dview.cxx
+++ b/sw/source/core/draw/dview.cxx
@@ -821,9 +821,9 @@ void SwDrawView::CheckPossibilities()
     {
         const SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
         const SwFrame *pFrame = nullptr;
-        if ( dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) !=  nullptr )
+        if ( auto pVirtFlyDrawObj = dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) )
         {
-            const SwFlyFrame *pFly = static_cast<const SwVirtFlyDrawObj*>(pObj)->GetFlyFrame();
+            const SwFlyFrame *pFly = pVirtFlyDrawObj->GetFlyFrame();
             if ( pFly  )
             {
                 pFrame = pFly->GetAnchorFrame();
diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx
index 72dbf52493da..9308d78c5afe 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -1426,10 +1426,10 @@ static bool lcl_IsControlGroup( const SdrObject *pObj )
     bool bRet = false;
     if(dynamic_cast<const SdrUnoObj*>( pObj) !=  nullptr)
         bRet = true;
-    else if( dynamic_cast<const SdrObjGroup*>( pObj) !=  nullptr )
+    else if( auto pObjGroup = dynamic_cast<const SdrObjGroup*>( pObj) )
     {
         bRet = true;
-        const SdrObjList *pLst = static_cast<const SdrObjGroup*>(pObj)->GetSubList();
+        const SdrObjList *pLst = pObjGroup->GetSubList();
         for ( size_t i = 0; i < pLst->GetObjCount(); ++i )
             if( !::lcl_IsControlGroup( pLst->GetObj( i ) ) )
                 return false;
@@ -1493,8 +1493,8 @@ const SdrObject* SwFEShell::GetBestObject( bool bNext, GotoObjFlags eType, bool
         if ( rMrkList.GetMarkCount() )
         {
             const SdrObject* pStartObj = rMrkList.GetMark(0)->GetMarkedSdrObj();
-            if( dynamic_cast<const SwVirtFlyDrawObj*>( pStartObj) !=  nullptr )
-                aPos = static_cast<const SwVirtFlyDrawObj*>(pStartObj)->GetFlyFrame()->getFrameArea().Pos();
+            if( auto pVirtFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>( pStartObj) )
+                aPos = pVirtFlyDrawObj->GetFlyFrame()->getFrameArea().Pos();
             else
                 aPos = pStartObj->GetSnapRect().TopLeft();
 
@@ -2378,10 +2378,9 @@ bool SwFEShell::IsGroupAllowed() const
             if ( bIsGroupAllowed )
             {
                 const SwFrame* pAnchorFrame = nullptr;
-                if ( dynamic_cast<const SwVirtFlyDrawObj*>( pObj) !=  nullptr )
+                if ( auto pVirtFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>( pObj) )
                 {
-                    const SwFlyFrame* pFlyFrame =
-                            static_cast<const SwVirtFlyDrawObj*>(pObj)->GetFlyFrame();
+                    const SwFlyFrame* pFlyFrame = pVirtFlyDrawObj->GetFlyFrame();
                     if ( pFlyFrame )
                     {
                         pAnchorFrame = pFlyFrame->GetAnchorFrame();
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 76bc2b14a944..dcf2458da246 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -632,10 +632,10 @@ void SwFormatPageDesc::SwClientNotify( const SwModify& rModify, const SfxHint& r
         const SwModify* pMod = GetDefinedIn();
         if ( pMod )
         {
-            if( dynamic_cast<const SwContentNode*>( pMod) !=  nullptr )
-                const_cast<SwContentNode*>(static_cast<const SwContentNode*>(pMod))->SetAttr( aDfltDesc );
-            else if( dynamic_cast<const SwFormat*>( pMod) !=  nullptr)
-                const_cast<SwFormat*>(static_cast<const SwFormat*>(pMod))->SetFormatAttr( aDfltDesc );
+            if( auto pContentNode = dynamic_cast<const SwContentNode*>( pMod) )
+                const_cast<SwContentNode*>(pContentNode)->SetAttr( aDfltDesc );
+            else if( auto pFormat = dynamic_cast<const SwFormat*>( pMod) )
+                const_cast<SwFormat*>(pFormat)->SetFormatAttr( aDfltDesc );
             else
             {
                 OSL_FAIL( "What kind of SwModify is this?" );
diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx
index b12bf063cd08..bf4f102b1409 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -309,9 +309,8 @@ sal_uInt8 SwFlowFrame::BwdMoveNecessary( const SwPageFrame *pPage, const SwRect
                 if( m_rThis.IsLayoutFrame() && //Fly Lower of This?
                     Is_Lower_Of( &m_rThis, pObj->GetDrawObj() ) )
                     continue;
-                if( dynamic_cast<const SwFlyFrame*>( pObj) !=  nullptr )
+                if( auto pFly = dynamic_cast<const SwFlyFrame*>(pObj) )
                 {
-                    const SwFlyFrame *pFly = static_cast<const SwFlyFrame*>(pObj);
                     if ( pFly->IsAnLower( &m_rThis ) )//This Lower of Fly?
                         continue;
                 }
diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx
index 0f47449e468a..f0ef660adb88 100644
--- a/sw/source/core/layout/flylay.cxx
+++ b/sw/source/core/layout/flylay.cxx
@@ -945,9 +945,9 @@ void SwPageFrame::PlaceFly( SwFlyFrame* pFly, SwFlyFrameFormat* pFormat )
 bool CalcClipRect( const SdrObject *pSdrObj, SwRect &rRect, bool bMove )
 {
     bool bRet = true;
-    if ( dynamic_cast<const SwVirtFlyDrawObj*>( pSdrObj) !=  nullptr )
+    if ( auto pVirtFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>(pSdrObj) )
     {
-        const SwFlyFrame* pFly = static_cast<const SwVirtFlyDrawObj*>(pSdrObj)->GetFlyFrame();
+        const SwFlyFrame* pFly = pVirtFlyDrawObj->GetFlyFrame();
         const bool bFollowTextFlow = pFly->GetFormat()->GetFollowTextFlow().GetValue();
         // #i28701#
         const bool bConsiderWrapOnObjPos =
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index 2da161f7b5ba..1c536f45aacd 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -2823,9 +2823,9 @@ void Notify_Background( const SdrObject* pObj,
     SwLayoutFrame* pArea;
     SwFlyFrame *pFlyFrame = nullptr;
     SwFrame* pAnchor;
-    if( dynamic_cast<const SwVirtFlyDrawObj*>( pObj) !=  nullptr )
+    if( auto pVirtFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>( pObj) )
     {
-        pFlyFrame = const_cast<SwVirtFlyDrawObj*>(static_cast<const SwVirtFlyDrawObj*>(pObj))->GetFlyFrame();
+        pFlyFrame = const_cast<SwVirtFlyDrawObj*>(pVirtFlyDrawObj)->GetFlyFrame();
         pAnchor = pFlyFrame->AnchorFrame();
     }
     else
diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index 6efbee92bc89..7b23377bb48d 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -893,9 +893,8 @@ static const SwFrame *lcl_FindFirstInvaContent( const SwLayoutFrame *pLay, long
             const SwSortedObjs &rObjs = *pCnt->GetDrawObjs();
             for (SwAnchoredObject* pObj : rObjs)
             {
-                if ( dynamic_cast< const SwFlyFrame *>( pObj ) !=  nullptr )
+                if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pObj ) )
                 {
-                    const SwFlyFrame* pFly = static_cast<const SwFlyFrame*>(pObj);
                     if ( pFly->IsFlyInContentFrame() )
                     {
                         if ( static_cast<const SwFlyInContentFrame*>(pFly)->IsInvalid() ||
@@ -928,9 +927,8 @@ static const SwAnchoredObject* lcl_FindFirstInvaObj( const SwPageFrame* _pPage,
 
     for (SwAnchoredObject* pObj : *_pPage->GetSortedObjs())
     {
-        if ( dynamic_cast< const SwFlyFrame *>( pObj ) !=  nullptr )
+        if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pObj )  )
         {
-            const SwFlyFrame* pFly = static_cast<const SwFlyFrame*>(pObj);
             if ( pFly->getFrameArea().Top() <= _nBottom )
             {
                 if ( pFly->IsInvalid() || pFly->IsCompletePaint() )
@@ -942,9 +940,9 @@ static const SwAnchoredObject* lcl_FindFirstInvaObj( const SwPageFrame* _pPage,
                     return pFly;
             }
         }
-        else if ( dynamic_cast< const SwAnchoredDrawObject *>( pObj ) !=  nullptr )
+        else if ( auto pDrawObject = dynamic_cast< const SwAnchoredDrawObject *>( pObj ) )
         {
-            if ( !static_cast<const SwAnchoredDrawObject*>(pObj)->IsValidPos() )
+            if ( !pDrawObject->IsValidPos() )
             {
                 return pObj;
             }
@@ -2018,9 +2016,8 @@ bool SwLayIdle::DoIdleJob( IdleJobType eJob, bool bVisAreaOnly )
                                 i < pPage->GetSortedObjs()->size(); ++i )
             {
                 const SwAnchoredObject* pObj = (*pPage->GetSortedObjs())[i];
-                if ( dynamic_cast< const SwFlyFrame *>( pObj ) !=  nullptr )
+                if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pObj ) )
                 {
-                    const SwFlyFrame *pFly = static_cast<const SwFlyFrame*>(pObj);
                     const SwContentFrame *pC = pFly->ContainsContent();
                     while( pC )
                     {
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index 0f88770afa8c..99cd4b342f1b 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -7051,9 +7051,8 @@ void SwPageFrame::RefreshExtraData( const SwRect &rRect ) const
         if ( bLineInFly && GetSortedObjs() )
             for (SwAnchoredObject* pAnchoredObj : *GetSortedObjs())
             {
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) )
                 {
-                    const SwFlyFrame *pFly = static_cast<const SwFlyFrame*>(pAnchoredObj);
                     if ( pFly->getFrameArea().Top() <= aRect.Bottom() &&
                          pFly->getFrameArea().Bottom() >= aRect.Top() )
                         pFly->RefreshExtraData( aRect );
@@ -7085,9 +7084,8 @@ void SwLayoutFrame::RefreshExtraData( const SwRect &rRect ) const
         if ( bLineInFly && pCnt->GetDrawObjs() )
             for (SwAnchoredObject* pAnchoredObj : *pCnt->GetDrawObjs())
             {
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) )
                 {
-                    const SwFlyFrame *pFly = static_cast<const SwFlyFrame*>(pAnchoredObj);
                     if ( pFly->IsFlyInContentFrame() &&
                          pFly->getFrameArea().Top() <= rRect.Bottom() &&
                          pFly->getFrameArea().Bottom() >= rRect.Top() )
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index cc3a2f8d0058..245d636b4552 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -5081,10 +5081,8 @@ void SwCellFrame::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorder
                     if ( bConsiderWrapOnObjPos || css::text::WrapTextMode_THROUGH != rSur.GetSurround() )
                     {
                         // frames, which the cell is a lower of, aren't relevant
-                        if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                        if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) )
                         {
-                            const SwFlyFrame *pFly =
-                                    static_cast<const SwFlyFrame*>(pAnchoredObj);
                             if ( pFly->IsAnLower( this ) )
                                 continue;
                         }
diff --git a/sw/source/core/text/txtfly.cxx b/sw/source/core/text/txtfly.cxx
index 7404f101e47a..fff55186d725 100644
--- a/sw/source/core/text/txtfly.cxx
+++ b/sw/source/core/text/txtfly.cxx
@@ -220,12 +220,12 @@ const SwRect SwContourCache::ContourRect( const SwFormat* pFormat,
         ::basegfx::B2DPolyPolygon aPolyPolygon;
         ::basegfx::B2DPolyPolygon* pPolyPolygon = nullptr;
 
-        if ( dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) !=  nullptr )
+        if ( auto pVirtFlyDrawObj = dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) )
         {
             // GetContour() causes the graphic to be loaded, which may cause
             // the graphic to change its size, call ClrObject()
             tools::PolyPolygon aPoly;
-            if( !static_cast<const SwVirtFlyDrawObj*>(pObj)->GetFlyFrame()->GetContour( aPoly ) )
+            if( !pVirtFlyDrawObj->GetFlyFrame()->GetContour( aPoly ) )
                 aPoly = tools::PolyPolygon( static_cast<const SwVirtFlyDrawObj*>(pObj)->
                                      GetFlyFrame()->getFrameArea().SVRect() );
             aPolyPolygon.clear();
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 7d81aa8a3b40..d907daa6ce6a 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1548,11 +1548,8 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any&
             {
                 // see SwFEShell::SetFrameFormat( SwFrameFormat *pNewFormat, bool bKeepOrient, Point* pDocPos )
                 SwFlyFrame *pFly = nullptr;
-                {
-                    const SwFrameFormat* pFormatXX = pFormat;
-                    if (dynamic_cast<const SwFlyFrameFormat*>( pFormatXX) )
-                        pFly = static_cast<const SwFlyFrameFormat*>(pFormatXX)->GetFrame();
-                }
+                if (auto pFlyFrameFormat = dynamic_cast<const SwFlyFrameFormat*>(pFormat) )
+                    pFly = pFlyFrameFormat->GetFrame();
                 if ( pFly )
                 {
                     const ::SfxPoolItem* pItem;
@@ -1933,8 +1930,8 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any&
                 {
                     // see SwFEShell::SetFlyFrameAttr( SfxItemSet& rSet )
                     SwFlyFrame *pFly = nullptr;
-                    if (dynamic_cast<SwFlyFrameFormat*>( pFormat) )
-                        pFly = static_cast<SwFlyFrameFormat*>(pFormat)->GetFrame();
+                    if (auto pFrameFormat = dynamic_cast<SwFlyFrameFormat*>( pFormat) )
+                        pFly = pFrameFormat->GetFrame();
                     if (pFly)
                     {
                         const ::SfxPoolItem* pItem;
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx
index e3fd77c077ff..467112e58956 100644
--- a/sw/source/uibase/app/apphdl.cxx
+++ b/sw/source/uibase/app/apphdl.cxx
@@ -974,9 +974,9 @@ void SwModule::ConfigurationChanged( utl::ConfigurationBroadcaster* pBrdCst, Con
         const SfxObjectShell* pObjSh = SfxObjectShell::GetFirst();
         while( pObjSh )
         {
-            if( dynamic_cast<const SwDocShell*>(pObjSh) !=  nullptr )
+            if( auto pDocShell = dynamic_cast<const SwDocShell*>(pObjSh) )
             {
-                SwDoc* pDoc = const_cast<SwDocShell*>(static_cast<const SwDocShell*>(pObjSh))->GetDoc();
+                SwDoc* pDoc = const_cast<SwDocShell*>(pDocShell)->GetDoc();
                 SwViewShell* pVSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
                 if ( pVSh )
                     pVSh->ChgNumberDigits();
diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx
index 445a4404eb2c..8f50bc411834 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -1147,8 +1147,8 @@ void SwDocShell::LoadingFinished()
     if(pVFrame)
     {
         SfxViewShell* pShell = pVFrame->GetViewShell();
-        if(dynamic_cast<SwSrcView*>( pShell) )
-            static_cast<SwSrcView*>(pShell)->Load(this);
+        if(auto pSrcView = dynamic_cast<SwSrcView*>( pShell) )
+            pSrcView->Load(this);
     }
 
     // #i38810#


More information about the Libreoffice-commits mailing list