sc/qa/unit/ucalc_formula.cxx        |   35 +++++++++++++++++++++++++++++++++++
 sc/source/core/data/formulacell.cxx |    3 +--
 2 files changed, 36 insertions(+), 2 deletions(-)

New commits:
commit d85334664cae22fa7bbc3852d260c0ca7ad704a2
Author:     Markus Mohrhard <markus.mohrh...@googlemail.com>
AuthorDate: Tue Aug 12 08:48:03 2025 +0800
Commit:     Markus Mohrhard <markus.mohrh...@googlemail.com>
CommitDate: Tue Aug 12 18:32:00 2025 +0200

    tdf#87058: handle column label references after inserting rows below title
    
    Change-Id: I49d066e6466b3bd1368903a150a596d8dc40226e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189425
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com>

diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 20e74f856d3e..fc39d635ba67 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -5109,6 +5109,41 @@ CPPUNIT_TEST_FIXTURE(TestFormula, testFuncCOUNTIF)
     m_pDoc->DeleteTab(0);
 }
 
+CPPUNIT_TEST_FIXTURE(TestFormula, testInsertRowColLabel)
+{
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, u"foo"_ustr));
+
+    // Clear the area first.
+    clearRange(m_pDoc, ScRange(0, 0, 0, 1, 20, 0));
+
+    m_pDoc->SetString(0, 2, 0, u"COL1"_ustr);
+    m_pDoc->SetValue(0, 3, 0, 2);
+    m_pDoc->SetValue(0, 4, 0, 3);
+    m_pDoc->SetString(0, 0, 0, u"=AVERAGE('COL1')"_ustr);
+
+    // Calculate and check the results.
+    m_pDoc->CalcAll();
+
+    double result = m_pDoc->GetValue(0, 0, 0);
+
+    ASSERT_DOUBLES_EQUAL(2.5, result);
+
+    m_pDoc->InsertRow(0, 0, m_pDoc->MaxCol(), 0, 3, 2);
+
+    m_pDoc->SetValue(0, 3, 0, 5);
+    m_pDoc->SetValue(0, 4, 0, 6);
+
+    // Calculate and check the results.
+    m_pDoc->CalcAll();
+
+    result = m_pDoc->GetValue(0, 0, 0);
+
+    ASSERT_DOUBLES_EQUAL(4.0, result);
+
+    m_pDoc->DeleteTab(0);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/formulacell.cxx 
b/sc/source/core/data/formulacell.cxx
index 832c0db8843c..590e599d91ed 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -3261,10 +3261,9 @@ bool ScFormulaCell::UpdateReferenceOnShift(
 
     // Check presence of any references or column row names.
     bool bHasRefs = pCode->HasReferences();
-    bool bHasColRowNames = false;
+    bool bHasColRowNames = 
(formula::FormulaTokenArrayPlainIterator(*pCode).GetNextColRowName() != 
nullptr);
     if (!bHasRefs)
     {
-        bHasColRowNames = 
(formula::FormulaTokenArrayPlainIterator(*pCode).GetNextColRowName() != 
nullptr);
         bHasRefs = bHasColRowNames;
     }
     bool bOnRefMove = pCode->IsRecalcModeOnRefMove();

Reply via email to