include/svl/itemset.hxx   |    9 +++------
 sc/qa/unit/ucalc_sort.cxx |   25 ++++++++++---------------
 2 files changed, 13 insertions(+), 21 deletions(-)

New commits:
commit 1e086712e4a991c0373168c75348075231be4301
Author:     Mike Kaganski <[email protected]>
AuthorDate: Mon Nov 24 13:18:10 2025 +0100
Commit:     Mike Kaganski <[email protected]>
CommitDate: Tue Nov 25 19:45:34 2025 +0100

    Drop templated HasItem in favor of GetItemIfSet
    
    ... and harden the latter using StaticWhichCast.
    
    Change-Id: If49674b7725624e2a0493b1891ada4de0ebc0cd0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194441
    Code-Style: Mike Kaganski <[email protected]>
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 8b63445a03a9..09e305ee88e8 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -201,16 +201,13 @@ public:
     const T *                   GetItemIfSet(   TypedWhichId<T> nWhich,
                                                 bool bSrchInParent = true ) 
const
     {
-        const T * pItem = nullptr;
-        if (SfxItemState::SET == GetItemState(nWhich, bSrchInParent, &pItem))
-            return pItem;
+        const SfxPoolItem* pItem = nullptr;
+        if (SfxItemState::SET == GetItemState(sal_uInt16(nWhich), 
bSrchInParent, &pItem))
+            return &pItem->StaticWhichCast(nWhich);
         return nullptr;
     }
 
     bool                        HasItem(sal_uInt16 nWhich, const SfxPoolItem** 
ppItem = nullptr) const;
-    template<class T>
-    bool                        HasItem(TypedWhichId<T> nWhich, const T** 
ppItem = nullptr) const
-    { return HasItem(sal_uInt16(nWhich), reinterpret_cast<const 
SfxPoolItem**>(ppItem)); }
     void                        CollectHasItems(std::vector<sal_uInt16>& 
rItemWhichs) const;
 
     void DisableItem(sal_uInt16 nWhich)
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index ccfecf633a69..5cd3fed5f0db 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -548,16 +548,14 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
                 return false;
             }
 
-            const SfxPoolItem* pItem = nullptr;
-            if (!pPat->GetItemSet().HasItem(ATTR_FONT_WEIGHT, &pItem))
+            const SvxWeightItem* pItem = 
pPat->GetItemSet().GetItemIfSet(ATTR_FONT_WEIGHT);
+            if (!pItem)
             {
                 std::cerr << "Pattern does not have a font weight item, but it 
should." << std::endl;
                 return false;
             }
 
-            CPPUNIT_ASSERT(pItem);
-
-            if (pItem->StaticWhichCast(ATTR_FONT_WEIGHT).GetWeight() != 
WEIGHT_BOLD)
+            if (pItem->GetWeight() != WEIGHT_BOLD)
             {
                 std::cerr << "Font weight should be bold." << std::endl;
                 return false;
@@ -574,16 +572,14 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
                 return false;
             }
 
-            const SfxPoolItem* pItem = nullptr;
-            if (!pPat->GetItemSet().HasItem(ATTR_FONT_POSTURE, &pItem))
+            const SvxPostureItem* pItem = 
pPat->GetItemSet().GetItemIfSet(ATTR_FONT_POSTURE);
+            if (!pItem)
             {
                 std::cerr << "Pattern does not have a font posture item, but 
it should." << std::endl;
                 return false;
             }
 
-            CPPUNIT_ASSERT(pItem);
-
-            if (pItem->StaticWhichCast(ATTR_FONT_POSTURE).GetPosture() != 
ITALIC_NORMAL)
+            if (pItem->GetPosture() != ITALIC_NORMAL)
             {
                 std::cerr << "Italic should be applied.." << std::endl;
                 return false;
@@ -600,21 +596,20 @@ CPPUNIT_TEST_FIXTURE(TestSort, testSortWithCellFormats)
                 return false;
             }
 
-            const SfxPoolItem* pItem = nullptr;
-            if (pPat->GetItemSet().HasItem(ATTR_FONT_WEIGHT, &pItem))
+            if (const SvxWeightItem* pItem = 
pPat->GetItemSet().GetItemIfSet(ATTR_FONT_WEIGHT))
             {
                 // Check if the font weight is applied.
-                if (pItem->StaticWhichCast(ATTR_FONT_WEIGHT).GetWeight() == 
WEIGHT_BOLD)
+                if (pItem->GetWeight() == WEIGHT_BOLD)
                 {
                     std::cerr << "This cell is bold, but shouldn't." << 
std::endl;
                     return false;
                 }
             }
 
-            if (pPat->GetItemSet().HasItem(ATTR_FONT_POSTURE, &pItem))
+            if (const SvxPostureItem* pItem = 
pPat->GetItemSet().GetItemIfSet(ATTR_FONT_POSTURE))
             {
                 // Check if the italics is applied.
-                if (pItem->StaticWhichCast(ATTR_FONT_POSTURE).GetPosture() == 
ITALIC_NORMAL)
+                if (pItem->GetPosture() == ITALIC_NORMAL)
                 {
                     std::cerr << "This cell is italic, but shouldn't." << 
std::endl;
                     return false;

Reply via email to