dbaccess/source/core/dataaccess/databasedocument.cxx     |    2 -
 include/editeng/txtrange.hxx                             |    3 -
 sc/qa/unit/ucalc.cxx                                     |   29 ++++++---------
 sc/qa/unit/ucalc_condformat.cxx                          |    4 +-
 sd/source/ui/view/drviews9.cxx                           |    2 -
 svx/source/toolbars/extrusionbar.cxx                     |    4 +-
 svx/source/toolbars/fontworkbar.cxx                      |    4 +-
 sw/source/core/frmedt/tblsel.cxx                         |   29 ++++-----------
 sw/source/core/txtnode/txtedt.cxx                        |    2 -
 sw/source/filter/ww8/ww8atr.cxx                          |    2 -
 sw/source/uibase/shells/grfsh.cxx                        |    2 -
 sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx |    3 -
 vcl/source/outdev/polygon.cxx                            |    4 +-
 13 files changed, 36 insertions(+), 54 deletions(-)

New commits:
commit e7cc35a41d74381b93313cb30b1ddb64378fc5c4
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Aug 17 10:24:12 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Aug 17 13:40:18 2025 +0200

    Drop needless const_casts
    
    Change-Id: I69a77bfe60c4554e71e3b24026d2f856236e3d43
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189814
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx 
b/dbaccess/source/core/dataaccess/databasedocument.cxx
index f0ba617914b3..e622e029842c 100644
--- a/dbaccess/source/core/dataaccess/databasedocument.cxx
+++ b/dbaccess/source/core/dataaccess/databasedocument.cxx
@@ -1514,7 +1514,7 @@ void SAL_CALL ODatabaseDocument::close(sal_Bool 
bDeliverOwnership)
 
         impl_closeControllerFrames_nolck_throw( bDeliverOwnership );
 
-        m_aCloseListener.notifyEach( &XCloseListener::notifyClosing, 
const_cast<const lang::EventObject&>(aEvent) );
+        m_aCloseListener.notifyEach(&XCloseListener::notifyClosing, aEvent);
 
         dispose();
     }
diff --git a/include/editeng/txtrange.hxx b/include/editeng/txtrange.hxx
index e495ae9f96de..d364fbb9d299 100644
--- a/include/editeng/txtrange.hxx
+++ b/include/editeng/txtrange.hxx
@@ -70,8 +70,7 @@ public:
     bool IsSimple() const { return bSimple; }
     bool IsInner() const { return bInner; }
     bool IsVertical() const { return bVertical; }
-    const tools::Rectangle& GetBoundRect() const
-        { return mxBound ? const_cast< const tools::Rectangle& >(*mxBound) : 
GetBoundRect_(); }
+    const tools::Rectangle& GetBoundRect() const { return mxBound ? *mxBound : 
GetBoundRect_(); }
     void SetUpper( sal_uInt16 nNew ){ nUpper = nNew; }
     void SetLower( sal_uInt16 nNew ){ nLower = nNew; }
     void SetVertical( bool bNew );
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index fd895fb64322..72a26a250005 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -3246,36 +3246,32 @@ CPPUNIT_TEST_FIXTURE(Test, testGraphicsInGroup)
         rtl::Reference<SdrRectObj> pObj = new SdrRectObj(*pDrawLayer, 
aOrigRect);
         pPage->InsertObject(pObj.get());
         const tools::Rectangle &rNewRect = pObj->GetLogicRect();
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("must have equal position and size",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("must have equal position and size", 
aOrigRect, rNewRect);
 
         ScDrawLayer::SetPageAnchored(*pObj);
 
         //Use a range of rows guaranteed to include all of the square
         m_pDoc->ShowRows(0, 100, 0, false);
         m_pDoc->SetDrawPageSize(0);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Should not change when page anchored",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Should not change when page anchored", 
aOrigRect, rNewRect);
         m_pDoc->ShowRows(0, 100, 0, true);
         m_pDoc->SetDrawPageSize(0);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Should not change when page anchored",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Should not change when page anchored", 
aOrigRect, rNewRect);
 
         ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, true);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("That shouldn't change size or 
positioning",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+                               aOrigRect, rNewRect);
 
         m_pDoc->ShowRows(0, 100, 0, false);
         m_pDoc->SetDrawPageSize(0);
 
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Hiding should not change the logic 
rectangle",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+                               aOrigRect, rNewRect);
         CPPUNIT_ASSERT_MESSAGE("Hiding should make invisible", 
!pObj->IsVisible());
 
         m_pDoc->ShowRows(0, 100, 0, true);
         m_pDoc->SetDrawPageSize(0);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Should not change when cell anchored",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Should not change when cell anchored", 
aOrigRect, rNewRect);
         CPPUNIT_ASSERT_MESSAGE("Show should make visible", pObj->IsVisible());
     }
 
@@ -3286,11 +3282,11 @@ CPPUNIT_TEST_FIXTURE(Test, testGraphicsInGroup)
         pPage->InsertObject(pObj.get());
         const tools::Rectangle& rNewRect = pObj->GetLogicRect();
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Position and size of the circle 
shouldn't change when inserted into the page.",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+                               aOrigRect, rNewRect);
 
         ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Size changed when cell anchored. Not 
good.",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+                               aOrigRect, rNewRect);
 
         // Insert 2 rows at the top.  This should push the circle object down.
         m_pDoc->InsertRow(0, 0, m_pDoc->MaxCol(), 0, 0, 2);
@@ -3304,7 +3300,7 @@ CPPUNIT_TEST_FIXTURE(Test, testGraphicsInGroup)
         m_pDoc->DeleteRow(0, 0, m_pDoc->MaxCol(), 0, 0, 2);
         m_pDoc->SetDrawPageSize(0);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to move back to its original 
position.",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+                               aOrigRect, rNewRect);
     }
 
     {
@@ -3318,19 +3314,18 @@ CPPUNIT_TEST_FIXTURE(Test, testGraphicsInGroup)
         pObj->NbcSetLogicRect(aOrigRect);
         pPage->InsertObject(pObj.get());
         const tools::Rectangle& rNewRect = pObj->GetLogicRect();
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Size differ.",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Size differ.", aOrigRect, rNewRect);
 
         ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Size changed when cell-anchored. Not 
good.",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+                               aOrigRect, rNewRect);
 
         // Insert 2 rows at the top and delete them immediately.
         m_pDoc->InsertRow(0, 0, m_pDoc->MaxCol(), 0, 0, 2);
         m_pDoc->DeleteRow(0, 0, m_pDoc->MaxCol(), 0, 0, 2);
         m_pDoc->SetDrawPageSize(0);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Size of a line object changed after row 
insertion and removal.",
-                               const_cast<const tools::Rectangle 
&>(aOrigRect), rNewRect);
+                               aOrigRect, rNewRect);
 
         sal_Int32 n = pObj->GetPointCount();
         CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly 2 points in a 
line object.", static_cast<sal_Int32>(2), n);
diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx
index e470fe8f5400..1dd7477729d6 100644
--- a/sc/qa/unit/ucalc_condformat.cxx
+++ b/sc/qa/unit/ucalc_condformat.cxx
@@ -201,8 +201,8 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testCondFormatInsertDeleteSheets)
     // Make sure this conditional format entry is really there.
     ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0);
     CPPUNIT_ASSERT(pList);
-    const ScConditionalFormat* pCheck = pList->GetFormat(nKey);
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong conditional format instance.", pCheck, 
const_cast<const ScConditionalFormat*>(pFormatTmp));
+    ScConditionalFormat* pCheck = pList->GetFormat(nKey);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong conditional format instance.", pCheck, 
pFormatTmp);
 
     // ... and its range is B2:B4.
     ScRangeList aCheckRange = pCheck->GetRange();
diff --git a/sd/source/ui/view/drviews9.cxx b/sd/source/ui/view/drviews9.cxx
index 9422ac4ca5cb..d13e7c9b9280 100644
--- a/sd/source/ui/view/drviews9.cxx
+++ b/sd/source/ui/view/drviews9.cxx
@@ -791,7 +791,7 @@ void DrawViewShell::AttrExec (SfxRequest &rReq)
             ;
     }
 
-    mpDrawView->SetAttributes (const_cast<const SfxItemSet &>(aAttr));
+    mpDrawView->SetAttributes (aAttr);
     rReq.Ignore ();
 }
 
diff --git a/svx/source/toolbars/extrusionbar.cxx 
b/svx/source/toolbars/extrusionbar.cxx
index dfd8c4a72780..3af209837379 100644
--- a/svx/source/toolbars/extrusionbar.cxx
+++ b/svx/source/toolbars/extrusionbar.cxx
@@ -658,8 +658,8 @@ void ExtrusionBar::execute( SdrView* pSdrView, SfxRequest 
const & rReq, SfxBindi
                     fDepth = aDlg.getDepth();
 
                     SvxDoubleItem aItem( fDepth, SID_EXTRUSION_DEPTH );
-                    SfxPoolItem* aItems[] = { &aItem, nullptr };
-                    rBindings.Execute( SID_EXTRUSION_DEPTH, const_cast<const 
SfxPoolItem**>(aItems) );
+                    const SfxPoolItem* aItems[] = { &aItem, nullptr };
+                    rBindings.Execute( SID_EXTRUSION_DEPTH, aItems );
                 }
             }
             break;
diff --git a/svx/source/toolbars/fontworkbar.cxx 
b/svx/source/toolbars/fontworkbar.cxx
index 740f93c278f5..11b5115fc95e 100644
--- a/svx/source/toolbars/fontworkbar.cxx
+++ b/svx/source/toolbars/fontworkbar.cxx
@@ -482,8 +482,8 @@ void FontworkBar::execute( SdrView& rSdrView, SfxRequest 
const & rReq, SfxBindin
                 if (nRet != RET_CANCEL)
                 {
                     SfxInt32Item aItem(SID_FONTWORK_CHARACTER_SPACING, 
aDlg.getScale());
-                    SfxPoolItem* aItems[] = { &aItem, nullptr };
-                    rBindings.Execute( SID_FONTWORK_CHARACTER_SPACING, 
const_cast<const SfxPoolItem**>(aItems) );
+                    const SfxPoolItem* aItems[] = { &aItem, nullptr };
+                    rBindings.Execute( SID_FONTWORK_CHARACTER_SPACING, aItems 
);
                 }
             }
         }
diff --git a/sw/source/core/frmedt/tblsel.cxx b/sw/source/core/frmedt/tblsel.cxx
index 5a685e6b0d2e..8312232de291 100644
--- a/sw/source/core/frmedt/tblsel.cxx
+++ b/sw/source/core/frmedt/tblsel.cxx
@@ -2122,8 +2122,7 @@ void FndBox_::SetTableLines( const SwSelBoxes &rBoxes, 
const SwTable &rTable )
         SwTableLine *pLine = rBoxes[i]->GetUpper();
         while ( pLine->GetUpper() )
             pLine = pLine->GetUpper()->GetUpper();
-        const sal_uInt16 nPos = rTable.GetTabLines().GetPos(
-                    const_cast<const SwTableLine*&>(pLine) ) + 1;
+        const sal_uInt16 nPos = rTable.GetTabLines().GetPos(pLine) + 1;
 
         OSL_ENSURE( nPos != USHRT_MAX, "TableLine not found." );
 
@@ -2182,8 +2181,7 @@ void FndBox_::DelFrames( SwTable &rTable )
         rTable.CheckRowSpan( m_pLineBefore, true );
     if ( m_pLineBefore )
     {
-        nStPos = rTable.GetTabLines().GetPos(
-                        const_cast<const SwTableLine*&>(m_pLineBefore) );
+        nStPos = rTable.GetTabLines().GetPos(m_pLineBefore);
         OSL_ENSURE( nStPos != USHRT_MAX, "The fox stole the line!" );
         ++nStPos;
     }
@@ -2191,8 +2189,7 @@ void FndBox_::DelFrames( SwTable &rTable )
         rTable.CheckRowSpan( m_pLineBehind, false );
     if ( m_pLineBehind )
     {
-        nEndPos = rTable.GetTabLines().GetPos(
-                        const_cast<const SwTableLine*&>(m_pLineBehind) );
+        nEndPos = rTable.GetTabLines().GetPos(m_pLineBehind);
         OSL_ENSURE( nEndPos != USHRT_MAX, "The fox stole the line!" );
         if (nEndPos != 0)
             --nEndPos;
@@ -2341,16 +2338,14 @@ void FndBox_::MakeFrames( SwTable &rTable )
 
     if ( m_pLineBefore )
     {
-        nStPos = rTable.GetTabLines().GetPos(
-                        const_cast<const SwTableLine*&>(m_pLineBefore) );
+        nStPos = rTable.GetTabLines().GetPos(m_pLineBefore);
         OSL_ENSURE( nStPos != USHRT_MAX, "Fox stole the line!" );
         ++nStPos;
 
     }
     if ( m_pLineBehind )
     {
-        nEndPos = rTable.GetTabLines().GetPos(
-                        const_cast<const SwTableLine*&>(m_pLineBehind) );
+        nEndPos = rTable.GetTabLines().GetPos(m_pLineBehind);
         OSL_ENSURE( nEndPos != USHRT_MAX, "Fox stole the line!" );
         --nEndPos;
     }
@@ -2420,10 +2415,10 @@ void FndBox_::MakeNewFrames( SwTable &rTable, const 
sal_uInt16 nNumber,
     // bBehind == true:  before  pLineBehind
     //         == false: after   pLineBefore
     const sal_uInt16 nBfPos = m_pLineBefore ?
-        rTable.GetTabLines().GetPos( const_cast<const 
SwTableLine*&>(m_pLineBefore) ) :
+        rTable.GetTabLines().GetPos( m_pLineBefore ) :
         USHRT_MAX;
     const sal_uInt16 nBhPos = m_pLineBehind ?
-        rTable.GetTabLines().GetPos( const_cast<const 
SwTableLine*&>(m_pLineBehind) ) :
+        rTable.GetTabLines().GetPos( m_pLineBehind ) :
         USHRT_MAX;
 
     //nNumber: how often did we insert
@@ -2563,19 +2558,13 @@ bool FndBox_::AreLinesToRestore( const SwTable &rTable 
) const
 
     sal_uInt16 nBfPos;
     if(m_pLineBefore)
-    {
-        const SwTableLine* rLBefore = const_cast<const 
SwTableLine*>(m_pLineBefore);
-        nBfPos = rTable.GetTabLines().GetPos( rLBefore );
-    }
+        nBfPos = rTable.GetTabLines().GetPos( m_pLineBefore );
     else
         nBfPos = USHRT_MAX;
 
     sal_uInt16 nBhPos;
     if(m_pLineBehind)
-    {
-        const SwTableLine* rLBehind = const_cast<const 
SwTableLine*>(m_pLineBehind);
-        nBhPos = rTable.GetTabLines().GetPos( rLBehind );
-    }
+        nBhPos = rTable.GetTabLines().GetPos( m_pLineBehind );
     else
         nBhPos = USHRT_MAX;
 
diff --git a/sw/source/core/txtnode/txtedt.cxx 
b/sw/source/core/txtnode/txtedt.cxx
index fe9276e3b308..a4386360e596 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -2392,7 +2392,7 @@ SwWrongList* SwTextNode::GetSmartTags()
 
 SwWrongList const* SwTextNode::GetSmartTags() const
 {
-    return const_cast<SwWrongList 
const*>(const_cast<SwTextNode*>(this)->GetSmartTags());
+    return const_cast<SwTextNode*>(this)->GetSmartTags();
 }
 
 void SwTextNode::SetWordCountDirty( bool bNew ) const
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 8807c02a4d42..4d36d91c512a 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -5129,7 +5129,7 @@ void AttributeOutputBase::FormatColumns( const 
SwFormatCol& rCol )
 
     // get the page width without borders !!
 
-    const SwFrameFormat* pFormat = GetExport( ).m_pCurrentPageDesc ? 
&GetExport( ).m_pCurrentPageDesc->GetMaster() : &const_cast<const 
SwDoc&>(GetExport().m_rDoc).GetPageDesc(0).GetMaster();
+    const SwFrameFormat* pFormat = GetExport( ).m_pCurrentPageDesc ? 
&GetExport( ).m_pCurrentPageDesc->GetMaster() : 
&GetExport().m_rDoc.GetPageDesc(0).GetMaster();
     const SvxFrameDirectionItem &frameDirection = pFormat->GetFrameDir();
     SwTwips nPageSize;
     if ( frameDirection.GetValue() == SvxFrameDirection::Vertical_RL_TB || 
frameDirection.GetValue() == SvxFrameDirection::Vertical_LR_TB )
diff --git a/sw/source/uibase/shells/grfsh.cxx 
b/sw/source/uibase/shells/grfsh.cxx
index 1749197a9b63..08da7a6091ac 100644
--- a/sw/source/uibase/shells/grfsh.cxx
+++ b/sw/source/uibase/shells/grfsh.cxx
@@ -217,7 +217,7 @@ void SwGrfShell::Execute(SfxRequest &rReq)
                     aCrop.SetBottom( o3tl::toTwips( 
aScaledCropedRectangle.Bottom(), o3tl::Length::mm100 ));
 
                     Graphic aCompressedGraphic( aDialog.GetCompressedGraphic() 
);
-                    rSh.ReRead(OUString(), OUString(), const_cast<const 
Graphic*>(&aCompressedGraphic));
+                    rSh.ReRead(OUString(), OUString(), &aCompressedGraphic);
 
                     rSh.SetAttrItem(aCrop);
                     rSh.SetAttrItem(aMirror);
diff --git a/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx 
b/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx
index 8a78a8f65879..74ae5ad44414 100644
--- a/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx
+++ b/sw/source/writerfilter/ooxml/OOXMLFastContextHandler.cxx
@@ -277,8 +277,7 @@ OOXMLFastContextHandler::createUnknownChildContext
  const OUString &,
  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
 {
-    return uno::Reference< xml::sax::XFastContextHandler >
-        (new OOXMLFastContextHandler(*const_cast<const OOXMLFastContextHandler 
*>(this)));
+    return uno::Reference<xml::sax::XFastContextHandler>(new 
OOXMLFastContextHandler(*this));
 }
 
 void SAL_CALL OOXMLFastContextHandler::characters
diff --git a/vcl/source/outdev/polygon.cxx b/vcl/source/outdev/polygon.cxx
index 6aa164037dd6..551c627322ef 100644
--- a/vcl/source/outdev/polygon.cxx
+++ b/vcl/source/outdev/polygon.cxx
@@ -337,7 +337,7 @@ void OutputDevice::ImplDrawPolyPolygon( sal_uInt16 nPoly, 
const tools::PolyPolyg
 
     sal_uInt32 aStackAry1[OUTDEV_POLYPOLY_STACKBUF];
     const Point* aStackAry2[OUTDEV_POLYPOLY_STACKBUF];
-    PolyFlags* aStackAry3[OUTDEV_POLYPOLY_STACKBUF];
+    const PolyFlags* aStackAry3[OUTDEV_POLYPOLY_STACKBUF];
     sal_uInt32* pPointAry;
     const Point**    pPointAryAry;
     const PolyFlags**  pFlagAryAry;
@@ -355,7 +355,7 @@ void OutputDevice::ImplDrawPolyPolygon( sal_uInt16 nPoly, 
const tools::PolyPolyg
     {
         pPointAry       = aStackAry1;
         pPointAryAry    = aStackAry2;
-        pFlagAryAry     = const_cast<const PolyFlags**>(aStackAry3);
+        pFlagAryAry     = aStackAry3;
     }
 
     do

Reply via email to