[Libreoffice-commits] core.git: formula/source include/formula sc/inc sc/qa sc/source

Noel Grandin noel at peralex.com
Fri Sep 23 15:25:02 UTC 2016


 formula/source/core/api/FormulaCompiler.cxx    |  108 ++--
 formula/source/core/api/token.cxx              |   16 
 include/formula/FormulaCompiler.hxx            |    7 
 include/formula/errorcodes.hxx                 |  106 ++--
 include/formula/token.hxx                      |   13 
 include/formula/tokenarray.hxx                 |   12 
 sc/inc/addincol.hxx                            |    4 
 sc/inc/column.hxx                              |    6 
 sc/inc/compiler.hxx                            |    6 
 sc/inc/dociter.hxx                             |   12 
 sc/inc/document.hxx                            |    9 
 sc/inc/formulacell.hxx                         |   12 
 sc/inc/formularesult.hxx                       |   14 
 sc/inc/global.hxx                              |   11 
 sc/inc/math.hxx                                |    2 
 sc/inc/rangenam.hxx                            |    2 
 sc/inc/scmatrix.hxx                            |   19 
 sc/inc/simpleformulacalc.hxx                   |    2 
 sc/inc/table.hxx                               |    9 
 sc/qa/unit/helper/qahelper.cxx                 |    4 
 sc/qa/unit/helper/shared_test_impl.hxx         |    5 
 sc/qa/unit/subsequent_filters-test.cxx         |    6 
 sc/qa/unit/ucalc.cxx                           |   10 
 sc/qa/unit/ucalc_formula.cxx                   |   48 -
 sc/qa/unit/ucalc_pivottable.cxx                |    6 
 sc/source/core/data/clipcontext.cxx            |    5 
 sc/source/core/data/column.cxx                 |   23 
 sc/source/core/data/column2.cxx                |   24 
 sc/source/core/data/column3.cxx                |   18 
 sc/source/core/data/conditio.cxx               |    3 
 sc/source/core/data/dbdocutl.cxx               |    2 
 sc/source/core/data/dociter.cxx                |   32 -
 sc/source/core/data/documen2.cxx               |    2 
 sc/source/core/data/documen4.cxx               |   10 
 sc/source/core/data/document.cxx               |   12 
 sc/source/core/data/dpcache.cxx                |    3 
 sc/source/core/data/dpoutput.cxx               |    2 
 sc/source/core/data/formulacell.cxx            |  117 ++--
 sc/source/core/data/global.cxx                 |  113 ++--
 sc/source/core/data/global2.cxx                |   12 
 sc/source/core/data/simpleformulacalc.cxx      |   16 
 sc/source/core/data/table2.cxx                 |    2 
 sc/source/core/data/table3.cxx                 |    6 
 sc/source/core/data/table4.cxx                 |   10 
 sc/source/core/data/validat.cxx                |    8 
 sc/source/core/inc/doubleref.hxx               |    7 
 sc/source/core/inc/interpre.hxx                |   38 -
 sc/source/core/opencl/formulagroupcl.cxx       |   16 
 sc/source/core/opencl/op_statistical.cxx       |   12 
 sc/source/core/tool/addincol.cxx               |   26 -
 sc/source/core/tool/cellform.cxx               |    8 
 sc/source/core/tool/chartarr.cxx               |    3 
 sc/source/core/tool/compiler.cxx               |  134 ++---
 sc/source/core/tool/consoli.cxx                |    2 
 sc/source/core/tool/detfunc.cxx                |    7 
 sc/source/core/tool/doubleref.cxx              |    8 
 sc/source/core/tool/formularesult.cxx          |   36 -
 sc/source/core/tool/interpr1.cxx               |  606 ++++++++++++-------------
 sc/source/core/tool/interpr2.cxx               |  156 +++---
 sc/source/core/tool/interpr3.cxx               |  196 ++++----
 sc/source/core/tool/interpr4.cxx               |  386 +++++++--------
 sc/source/core/tool/interpr5.cxx               |  156 +++---
 sc/source/core/tool/interpr6.cxx               |   94 +--
 sc/source/core/tool/interpr7.cxx               |   28 -
 sc/source/core/tool/interpr8.cxx               |   80 +--
 sc/source/core/tool/jumpmatrix.cxx             |    6 
 sc/source/core/tool/rangenam.cxx               |   12 
 sc/source/core/tool/rangeseq.cxx               |    8 
 sc/source/core/tool/scmatrix.cxx               |   92 +--
 sc/source/core/tool/token.cxx                  |   22 
 sc/source/filter/dif/difexp.cxx                |    3 
 sc/source/filter/excel/excform.cxx             |   38 -
 sc/source/filter/excel/xeformula.cxx           |    7 
 sc/source/filter/excel/xehelper.cxx            |    3 
 sc/source/filter/excel/xelink.cxx              |    2 
 sc/source/filter/excel/xestream.cxx            |    2 
 sc/source/filter/excel/xetable.cxx             |    5 
 sc/source/filter/excel/xihelper.cxx            |    4 
 sc/source/filter/excel/xltools.cxx             |   55 +-
 sc/source/filter/inc/scflt.hxx                 |    6 
 sc/source/filter/inc/xihelper.hxx              |    2 
 sc/source/filter/inc/xltools.hxx               |    5 
 sc/source/filter/oox/defnamesbuffer.cxx        |    2 
 sc/source/filter/starcalc/scflt.cxx            |    3 
 sc/source/filter/xml/xmlexprt.cxx              |    3 
 sc/source/filter/xml/xmlimprt.cxx              |    3 
 sc/source/ui/app/inputhdl.cxx                  |    5 
 sc/source/ui/app/scmod.cxx                     |    2 
 sc/source/ui/app/transobj.cxx                  |    5 
 sc/source/ui/condformat/condformatdlgentry.cxx |    3 
 sc/source/ui/docshell/docsh.cxx                |    5 
 sc/source/ui/docshell/externalrefmgr.cxx       |   30 -
 sc/source/ui/formdlg/formula.cxx               |    5 
 sc/source/ui/inc/tabvwsh.hxx                   |    3 
 sc/source/ui/namedlg/namedefdlg.cxx            |    6 
 sc/source/ui/namedlg/namedlg.cxx               |    4 
 sc/source/ui/unoobj/cellsuno.cxx               |    8 
 sc/source/ui/unoobj/chart2uno.cxx              |    4 
 sc/source/ui/unoobj/funcuno.cxx                |    6 
 sc/source/ui/view/cellsh.cxx                   |    4 
 sc/source/ui/view/output2.cxx                  |    2 
 sc/source/ui/view/tabvwsha.cxx                 |    6 
 sc/source/ui/view/viewfunc.cxx                 |   12 
 103 files changed, 1643 insertions(+), 1618 deletions(-)

New commits:
commit 3e22dfa5eb1ccebdc719a671d23bde7ccab256fb
Author: Noel Grandin <noel at peralex.com>
Date:   Wed Sep 14 15:22:20 2016 +0200

    convert formula error codes to scoped enum
    
    Change-Id: I5ff214bf1ec9031e30344bc125bc99916fd11bfb
    Reviewed-on: https://gerrit.libreoffice.org/28897
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index be19fcf..b0a2ada 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1150,9 +1150,9 @@ void FormulaCompiler::OpCodeMap::copyFrom( const OpCodeMap& r )
 }
 
 
-sal_uInt16 FormulaCompiler::GetErrorConstant( const OUString& rName ) const
+FormulaError FormulaCompiler::GetErrorConstant( const OUString& rName ) const
 {
-    sal_uInt16 nError = 0;
+    FormulaError nError = FormulaError::NONE;
     OpCodeHashMap::const_iterator iLook( mxSymbols->getHashMap()->find( rName));
     if (iLook != mxSymbols->getHashMap()->end())
     {
@@ -1161,25 +1161,25 @@ sal_uInt16 FormulaCompiler::GetErrorConstant( const OUString& rName ) const
             // Not all may make sense in a formula, but these we know as
             // opcodes.
             case ocErrNull:
-                nError = errNoCode;
+                nError = FormulaError::NoCode;
                 break;
             case ocErrDivZero:
-                nError = errDivisionByZero;
+                nError = FormulaError::DivisionByZero;
                 break;
             case ocErrValue:
-                nError = errNoValue;
+                nError = FormulaError::NoValue;
                 break;
             case ocErrRef:
-                nError = errNoRef;
+                nError = FormulaError::NoRef;
                 break;
             case ocErrName:
-                nError = errNoName;
+                nError = FormulaError::NoName;
                 break;
             case ocErrNum:
-                nError = errIllegalFPOperation;
+                nError = FormulaError::IllegalFPOperation;
                 break;
             case ocErrNA:
-                nError = NOTAVAILABLE;
+                nError = FormulaError::NotAvailable;
                 break;
             default:
                 ;   // nothing
@@ -1198,31 +1198,31 @@ void FormulaCompiler::EnableStopOnError( bool bEnable )
     mbStopOnError = bEnable;
 }
 
-void FormulaCompiler::AppendErrorConstant( OUStringBuffer& rBuffer, sal_uInt16 nError ) const
+void FormulaCompiler::AppendErrorConstant( OUStringBuffer& rBuffer, FormulaError nError ) const
 {
     OpCode eOp;
     switch (nError)
     {
         default:
-        case errNoCode:
+        case FormulaError::NoCode:
             eOp = ocErrNull;
             break;
-        case errDivisionByZero:
+        case FormulaError::DivisionByZero:
             eOp = ocErrDivZero;
             break;
-        case errNoValue:
+        case FormulaError::NoValue:
             eOp = ocErrValue;
             break;
-        case errNoRef:
+        case FormulaError::NoRef:
             eOp = ocErrRef;
             break;
-        case errNoName:
+        case FormulaError::NoName:
             eOp = ocErrName;
             break;
-        case errIllegalFPOperation:
+        case FormulaError::IllegalFPOperation:
             eOp = ocErrNum;
             break;
-        case NOTAVAILABLE:
+        case FormulaError::NotAvailable:
             eOp = ocErrNA;
             break;
     }
@@ -1242,7 +1242,7 @@ bool FormulaCompiler::GetToken()
     FormulaCompilerRecursionGuard aRecursionGuard( nRecursion );
     if ( nRecursion > nRecursionMax )
     {
-        SetError( errStackOverflow );
+        SetError( FormulaError::StackOverflow );
         mpToken = new FormulaByteToken( ocStop );
         return false;
     }
@@ -1252,7 +1252,7 @@ bool FormulaCompiler::GetToken()
         aCorrectedSymbol.clear();
     }
     bool bStop = false;
-    if (pArr->GetCodeError() && mbStopOnError)
+    if (pArr->GetCodeError() != FormulaError::NONE && mbStopOnError)
         bStop = true;
     else
     {
@@ -1343,7 +1343,7 @@ bool FormulaCompiler::GetToken()
 // RPN creation by recursion
 void FormulaCompiler::Factor()
 {
-    if (pArr->GetCodeError() && mbStopOnError)
+    if (pArr->GetCodeError() != FormulaError::NONE && mbStopOnError)
         return;
 
     CurrentFactor pFacToken( this );
@@ -1363,7 +1363,7 @@ void FormulaCompiler::Factor()
             SetError(
                 ( mpToken->GetType() == svString
                || mpToken->GetType() == svSingleRef )
-               ? errNoName : errOperatorExpected );
+               ? FormulaError::NoName : FormulaError::OperatorExpected );
             if ( bAutoCorrect && !pStack )
             {   // assume multiplication
                 aCorrectedFormula += mxSymbols->getSymbol( ocMul);
@@ -1371,7 +1371,7 @@ void FormulaCompiler::Factor()
                 NextToken();
                 eOp = Expression();
                 if( eOp != ocClose )
-                    SetError( errPairExpected);
+                    SetError( FormulaError::PairExpected);
                 else
                     NextToken();
             }
@@ -1381,7 +1381,7 @@ void FormulaCompiler::Factor()
     {
         NextToken();
         eOp = Expression();
-        while ((eOp == ocSep) && (!pArr->GetCodeError() || !mbStopOnError))
+        while ((eOp == ocSep) && (pArr->GetCodeError() == FormulaError::NONE || !mbStopOnError))
         {   // range list  (A1;A2)  converted to  (A1~A2)
             pFacToken = mpToken;
             NextToken();
@@ -1389,14 +1389,14 @@ void FormulaCompiler::Factor()
             eOp = Expression();
             // Do not ignore error here, regardless of bIgnoreErrors, otherwise
             // errors like =(1;) would also result in display of =(1~)
-            if (!pArr->GetCodeError())
+            if (pArr->GetCodeError() == FormulaError::NONE)
             {
                 pFacToken->NewOpCode( ocUnion, FormulaToken::PrivateAccess());
                 PutCode( pFacToken);
             }
         }
         if (eOp != ocClose)
-            SetError( errPairExpected);
+            SetError( FormulaError::PairExpected);
         else
             NextToken();
     }
@@ -1448,14 +1448,14 @@ void FormulaCompiler::Factor()
             eOp = NextToken();
             if (eOp != ocOpen)
             {
-                SetError( errPairExpected);
+                SetError( FormulaError::PairExpected);
                 PutCode( pFacToken );
             }
             else
             {
                 eOp = NextToken();
                 if (eOp != ocClose)
-                    SetError( errPairExpected);
+                    SetError( FormulaError::PairExpected);
                 PutCode( pFacToken);
                 NextToken();
             }
@@ -1483,13 +1483,13 @@ void FormulaCompiler::Factor()
                     }
                 }
                 else
-                    SetError( errPairExpected);
+                    SetError( FormulaError::PairExpected);
                 sal_uInt8 nSepCount = 0;
                 const sal_uInt16 nSepPos = pArr->nIndex - 1;    // separator position, if any
                 if( !bNoParam )
                 {
                     nSepCount++;
-                    while ((eOp == ocSep) && (!pArr->GetCodeError() || !mbStopOnError))
+                    while ((eOp == ocSep) && (pArr->GetCodeError() == FormulaError::NONE || !mbStopOnError))
                     {
                         NextToken();
                         CheckSetForceArrayParameter( mpToken, nSepCount);
@@ -1498,7 +1498,7 @@ void FormulaCompiler::Factor()
                     }
                 }
                 if (eOp != ocClose)
-                    SetError( errPairExpected);
+                    SetError( FormulaError::PairExpected);
                 else
                     NextToken();
                 pFacToken->SetByte( nSepCount );
@@ -1547,10 +1547,10 @@ void FormulaCompiler::Factor()
                     eOp = Expression();
                 }
                 else
-                    SetError( errPairExpected);
+                    SetError( FormulaError::PairExpected);
                 if (eOp != ocClose)
-                    SetError( errPairExpected);
-                else if ( !pArr->GetCodeError() )
+                    SetError( FormulaError::PairExpected);
+                else if ( pArr->GetCodeError() == FormulaError::NONE )
                     pFacToken->SetByte( 1 );
                 PutCode( pFacToken );
                 NextToken();
@@ -1589,12 +1589,12 @@ void FormulaCompiler::Factor()
                 bNoParam = true;
             }
             else
-                SetError( errPairExpected);
+                SetError( FormulaError::PairExpected);
             sal_uInt8 nSepCount = 0;
             if( !bNoParam )
             {
                 nSepCount++;
-                while ((eOp == ocSep) && (!pArr->GetCodeError() || !mbStopOnError))
+                while ((eOp == ocSep) && (pArr->GetCodeError() == FormulaError::NONE || !mbStopOnError))
                 {
                     NextToken();
                     CheckSetForceArrayParameter( mpToken, nSepCount);
@@ -1605,7 +1605,7 @@ void FormulaCompiler::Factor()
             if (bBadName)
                 ;   // nothing, keep current token for return
             else if (eOp != ocClose)
-                SetError( errPairExpected);
+                SetError( FormulaError::PairExpected);
             else
                 NextToken();
             // Jumps are just normal functions for the FunctionAutoPilot tree view
@@ -1643,7 +1643,7 @@ void FormulaCompiler::Factor()
                 eOp = Expression();
             }
             else
-                SetError( errPairExpected);
+                SetError( FormulaError::PairExpected);
             PutCode( pFacToken );
             // During AutoCorrect (since pArr->GetCodeError() is
             // ignored) an unlimited ocIf would crash because
@@ -1670,7 +1670,7 @@ void FormulaCompiler::Factor()
             }
             short nJumpCount = 0;
             while ( (nJumpCount < (FORMULA_MAXJUMPCOUNT - 1)) && (eOp == ocSep)
-                    && (!pArr->GetCodeError() || !mbStopOnError))
+                    && (pArr->GetCodeError() == FormulaError::NONE || !mbStopOnError))
             {
                 if ( ++nJumpCount <= nJumpMax )
                     pFacToken->GetJump()[nJumpCount] = pc-1;
@@ -1681,7 +1681,7 @@ void FormulaCompiler::Factor()
                 PutCode( mpToken );
             }
             if (eOp != ocClose)
-                SetError( errPairExpected);
+                SetError( FormulaError::PairExpected);
             else
             {
                 NextToken();
@@ -1710,7 +1710,7 @@ void FormulaCompiler::Factor()
                 if (bLimitOk)
                     pFacToken->GetJump()[ 0 ] = nJumpCount;
                 else
-                    SetError( errIllegalParameter);
+                    SetError( FormulaError::IllegalParameter);
             }
         }
         else if ( eOp == ocMissing )
@@ -1720,11 +1720,11 @@ void FormulaCompiler::Factor()
         }
         else if ( eOp == ocClose )
         {
-            SetError( errParameterExpected );
+            SetError( FormulaError::ParameterExpected );
         }
         else if ( eOp == ocSep )
         {   // Subsequent ocSep
-            SetError( errParameterExpected );
+            SetError( FormulaError::ParameterExpected );
             if ( bAutoCorrect && !pStack )
             {
                 aCorrectedSymbol.clear();
@@ -1738,7 +1738,7 @@ void FormulaCompiler::Factor()
         }
         else
         {
-            SetError( errUnknownToken );
+            SetError( FormulaError::UnknownToken );
             if ( bAutoCorrect && !pStack )
             {
                 if ( eOp == ocStop )
@@ -1918,7 +1918,7 @@ OpCode FormulaCompiler::Expression()
     FormulaCompilerRecursionGuard aRecursionGuard( nRecursion );
     if ( nRecursion > nRecursionMax )
     {
-        SetError( errStackOverflow );
+        SetError( FormulaError::StackOverflow );
         return ocStop;      //! generate token instead?
     }
     NotLine();
@@ -1934,7 +1934,7 @@ OpCode FormulaCompiler::Expression()
 }
 
 
-void FormulaCompiler::SetError( sal_uInt16 /*nError*/ )
+void FormulaCompiler::SetError( FormulaError /*nError*/ )
 {
 }
 
@@ -1967,7 +1967,7 @@ bool FormulaCompiler::CompileTokenArray()
 {
     glSubTotal = false;
     bCorrected = false;
-    if (!pArr->GetCodeError() || !mbStopOnError)
+    if (pArr->GetCodeError() == FormulaError::NONE || !mbStopOnError)
     {
         if ( bAutoCorrect )
         {
@@ -1992,9 +1992,9 @@ bool FormulaCompiler::CompileTokenArray()
         OpCode eOp = Expression();
         // Some trailing garbage that doesn't form an expression?
         if (eOp != ocStop)
-            SetError( errOperatorExpected);
+            SetError( FormulaError::OperatorExpected);
 
-        sal_uInt16 nErrorBeforePop = pArr->GetCodeError();
+        FormulaError nErrorBeforePop = pArr->GetCodeError();
 
         while( pStack )
             PopTokenArray();
@@ -2006,10 +2006,10 @@ bool FormulaCompiler::CompileTokenArray()
         }
 
         // once an error, always an error
-        if( !pArr->GetCodeError() && nErrorBeforePop )
+        if( pArr->GetCodeError() == FormulaError::NONE && nErrorBeforePop != FormulaError::NONE )
             pArr->SetCodeError( nErrorBeforePop);
 
-        if (pArr->GetCodeError() && mbStopOnError)
+        if (pArr->GetCodeError() != FormulaError::NONE && mbStopOnError)
         {
             pArr->DelRPN();
             pArr->SetHyperLink( false);
@@ -2361,7 +2361,7 @@ OpCode FormulaCompiler::NextToken()
     if ( (eOp == ocPush || eOp == ocColRowNameAuto) &&
             !( (eLastOp == ocOpen) || (eLastOp == ocSep) ||
                 (SC_OPCODE_START_BIN_OP <= eLastOp && eLastOp < SC_OPCODE_STOP_UN_OP)) )
-        SetError( errOperatorExpected);
+        SetError( FormulaError::OperatorExpected);
     // Operator and Plus => operator
     if (eOp == ocAdd && (eLastOp == ocOpen || eLastOp == ocSep ||
                 (SC_OPCODE_START_BIN_OP <= eLastOp && eLastOp < SC_OPCODE_STOP_UN_OP)))
@@ -2375,7 +2375,7 @@ OpCode FormulaCompiler::NextToken()
                 && (eLastOp == ocOpen || eLastOp == ocSep ||
                     (SC_OPCODE_START_BIN_OP <= eLastOp && eLastOp < SC_OPCODE_STOP_UN_OP)))
         {
-            SetError( errVariableExpected);
+            SetError( FormulaError::VariableExpected);
             if ( bAutoCorrect && !pStack )
             {
                 if ( eOp == eLastOp || eLastOp == ocOpen )
@@ -2476,10 +2476,10 @@ void FormulaCompiler::PutCode( FormulaTokenRef& p )
             *pCode++ = p.get();
             ++pc;
         }
-        SetError( errCodeOverflow);
+        SetError( FormulaError::CodeOverflow);
         return;
     }
-    if (pArr->GetCodeError() && mbJumpCommandReorder)
+    if (pArr->GetCodeError() != FormulaError::NONE && mbJumpCommandReorder)
         return;
     ForceArrayOperator( p);
     p->IncRef();
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index f8d7a9d..7d5528c 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -28,6 +28,7 @@
 #include <osl/diagnose.h>
 
 #include <com/sun/star/sheet/FormulaToken.hpp>
+#include "formula/errorcodes.hxx"
 #include "formula/token.hxx"
 #include "formula/tokenarray.hxx"
 #include "formula/FormulaCompiler.hxx"
@@ -262,13 +263,13 @@ FormulaToken* FormulaToken::GetFAPOrigToken() const
     return nullptr;
 }
 
-sal_uInt16 FormulaToken::GetError() const
+FormulaError FormulaToken::GetError() const
 {
     SAL_WARN( "formula.core", "FormulaToken::GetError: virtual dummy called" );
-    return 0;
+    return FormulaError::NONE;
 }
 
-void FormulaToken::SetError( sal_uInt16 )
+void FormulaToken::SetError( FormulaError )
 {
     SAL_WARN( "formula.core", "FormulaToken::SetError: virtual dummy called" );
 }
@@ -719,7 +720,7 @@ FormulaTokenArray::FormulaTokenArray() :
     nLen(0),
     nRPN(0),
     nIndex(0),
-    nError(0),
+    nError(FormulaError::NONE),
     nMode(ScRecalcMode::NORMAL),
     bHyperLink(false),
     mbFromRangeName(false)
@@ -802,7 +803,8 @@ void FormulaTokenArray::Clear()
         delete [] pCode;
     }
     pCode = nullptr; pRPN = nullptr;
-    nError = nLen = nIndex = nRPN = 0;
+    nError = FormulaError::NONE;
+    nLen = nIndex = nRPN = 0;
     bHyperLink = false;
     mbFromRangeName = false;
     ClearRecalcMode();
@@ -1802,8 +1804,8 @@ bool FormulaExternalToken::operator==( const FormulaToken& r ) const
 }
 
 
-sal_uInt16      FormulaErrorToken::GetError() const             { return nError; }
-void            FormulaErrorToken::SetError( sal_uInt16 nErr )  { nError = nErr; }
+FormulaError      FormulaErrorToken::GetError() const             { return nError; }
+void            FormulaErrorToken::SetError( FormulaError nErr )  { nError = nErr; }
 bool FormulaErrorToken::operator==( const FormulaToken& r ) const
 {
     return FormulaToken::operator==( r ) &&
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx
index 5d0e3da..e7268f6 100644
--- a/include/formula/FormulaCompiler.hxx
+++ b/include/formula/FormulaCompiler.hxx
@@ -48,6 +48,7 @@ namespace com { namespace sun { namespace star {
 }}}
 
 class CharClass;
+enum class FormulaError : sal_uInt16;
 
 namespace formula
 {
@@ -219,7 +220,7 @@ public:
      */
     OpCode GetEnglishOpCode( const OUString& rName ) const;
 
-    sal_uInt16 GetErrorConstant( const OUString& rName ) const;
+    FormulaError GetErrorConstant( const OUString& rName ) const;
 
     void EnableJumpCommandReorder( bool bEnable );
     void EnableStopOnError( bool bEnable );
@@ -279,7 +280,7 @@ protected:
     virtual void fillFromAddInCollectionEnglishName( const NonConstOpCodeMapPtr& xMap ) const;
     virtual void fillAddInToken(::std::vector< css::sheet::FormulaOpCodeMapEntry >& _rVec, bool _bIsEnglish) const;
 
-    virtual void SetError(sal_uInt16 nError);
+    virtual void SetError(FormulaError nError);
     virtual FormulaTokenRef ExtendRangeReference( FormulaToken & rTok1, FormulaToken & rTok2 );
     virtual bool HandleExternalReference(const FormulaToken& _aToken);
     virtual bool HandleRange();
@@ -298,7 +299,7 @@ protected:
         Calc: ForceArray or ReferenceOrForceArray type. */
     virtual bool IsForceArrayParameter( const FormulaToken* pToken, sal_uInt16 nParam ) const;
 
-    void AppendErrorConstant( OUStringBuffer& rBuffer, sal_uInt16 nError ) const;
+    void AppendErrorConstant( OUStringBuffer& rBuffer, FormulaError nError ) const;
 
     bool   GetToken();
     OpCode NextToken();
diff --git a/include/formula/errorcodes.hxx b/include/formula/errorcodes.hxx
index e4732b3..329be0d 100644
--- a/include/formula/errorcodes.hxx
+++ b/include/formula/errorcodes.hxx
@@ -24,99 +24,101 @@
 #include <sal/mathconf.h>
 #include <sal/types.h>
 
-namespace formula {
+// Store as 16-bits, since error values are stored in tokens and formula results,
+// and that can matter
+enum class FormulaError : sal_uInt16
+{
+    NONE                 = 0,
 
-const sal_uInt16 errIllegalChar          = 501;
-const sal_uInt16 errIllegalArgument      = 502;
-const sal_uInt16 errIllegalFPOperation   = 503; // #NUM!
-const sal_uInt16 errIllegalParameter     = 504;
-const sal_uInt16 errIllegalJump          = 505;
-const sal_uInt16 errSeparator            = 506;
-const sal_uInt16 errPair                 = 507;
-const sal_uInt16 errPairExpected         = 508;
-const sal_uInt16 errOperatorExpected     = 509;
-const sal_uInt16 errVariableExpected     = 510;
-const sal_uInt16 errParameterExpected    = 511;
-const sal_uInt16 errCodeOverflow         = 512;
-const sal_uInt16 errStringOverflow       = 513;
-const sal_uInt16 errStackOverflow        = 514;
-const sal_uInt16 errUnknownState         = 515;
-const sal_uInt16 errUnknownVariable      = 516;
-const sal_uInt16 errUnknownOpCode        = 517;
-const sal_uInt16 errUnknownStackVariable = 518;
-const sal_uInt16 errNoValue              = 519; // #VALUE!
-const sal_uInt16 errUnknownToken         = 520;
-const sal_uInt16 errNoCode               = 521; // #NULL!
-const sal_uInt16 errCircularReference    = 522;
-const sal_uInt16 errNoConvergence        = 523;
-const sal_uInt16 errNoRef                = 524; // #REF!
-const sal_uInt16 errNoName               = 525; // #NAME?
-const sal_uInt16 errDoubleRef            = 526;
+    IllegalChar          = 501,
+    IllegalArgument      = 502,
+    IllegalFPOperation   = 503, // #NUM!
+    IllegalParameter     = 504,
+    IllegalJump          = 505,
+    Separator            = 506,
+    Pair                 = 507,
+    PairExpected         = 508,
+    OperatorExpected     = 509,
+    VariableExpected     = 510,
+    ParameterExpected    = 511,
+    CodeOverflow         = 512,
+    StringOverflow       = 513,
+    StackOverflow        = 514,
+    UnknownState         = 515,
+    UnknownVariable      = 516,
+    UnknownOpCode        = 517,
+    UnknownStackVariable = 518,
+    NoValue              = 519, // #VALUE!
+    UnknownToken         = 520,
+    NoCode               = 521, // #NULL!
+    CircularReference    = 522,
+    NoConvergence        = 523,
+    NoRef                = 524, // #REF!
+    NoName               = 525, // #NAME?
+    DoubleRef            = 526,
 // Not displayed, temporary for TrackFormulas,
-// Cell depends on another cell that has errCircularReference
-const sal_uInt16 errTrackFromCircRef     = 528;
+// Cell depends on another cell that has FormulaError::CircularReference
+    TrackFromCircRef     = 528,
 // ScInterpreter internal:  no numeric value but numeric queried. If this is
 // set as mnStringNoValueError no error is generated but 0 returned.
-const sal_uInt16 errCellNoValue          = 529;
+    CellNoValue          = 529,
 // Interpreter: needed AddIn not found
-const sal_uInt16 errNoAddin              = 530;
+    NoAddin              = 530,
 // Interpreter: needed Macro not found
-const sal_uInt16 errNoMacro              = 531;
+    NoMacro              = 531,
 // Interpreter: Division by zero
-const sal_uInt16 errDivisionByZero       = 532; // #DIV/0!
+    DivisionByZero       = 532, // #DIV/0!
 // Compiler: a non-simple (str,err,val) value was put in an array
-const sal_uInt16 errNestedArray          = 533;
+    NestedArray          = 533,
 // ScInterpreter internal:  no numeric value but numeric queried. If this is
 // temporarily (!) set as mnStringNoValueError, the error is generated and can
 // be used to distinguish that condition from all other (inherited) errors. Do
 // not use for anything else! Never push or inherit the error otherwise!
-const sal_uInt16 errNotNumericString     = 534;
+    NotNumericString     = 534,
 // ScInterpreter internal:  jump matrix already has a result at this position,
 // do not overwrite in case of empty code path.
-const sal_uInt16 errJumpMatHasResult     = 535;
+    JumpMatHasResult     = 535,
 // ScInterpreter internal:  (matrix) element is not a numeric value, i.e.
-// string or empty, to be distinguished from the general errNoValue NAN and not
+// string or empty, to be distinguished from the general FormulaError::NoValue NAN and not
 // to be used as result.
-const sal_uInt16 errElementNaN           = 536;
+    ElementNaN           = 536,
 // ScInterpreter/ScFormulaCell internal:  keep dirty, retry interpreting next
 // round.
-const sal_uInt16 errRetryCircular        = 537;
+    RetryCircular        = 537,
 // If matrix could not be allocated.
-const sal_uInt16 errMatrixSize           = 538;
+    MatrixSize           = 538,
 
 // Interpreter: NA() not available condition, not a real error
-const sal_uInt16 NOTAVAILABLE            = 0x7fff;
-
+    NotAvailable         = 0x7fff
+};
 
 /** Unconditionally construct a double value of NAN where the lower bits
     represent an interpreter error code. */
-inline double CreateDoubleError( sal_uInt16 nErr )
+inline double CreateDoubleError( FormulaError nErr )
 {
     sal_math_Double smVal;
     ::rtl::math::setNan( &smVal.value );
-    smVal.nan_parts.fraction_lo = nErr;
+    smVal.nan_parts.fraction_lo = static_cast<unsigned>(nErr);
     return smVal.value;
 }
 
 /** Recreate the error code of a coded double error, if any. */
-inline sal_uInt16 GetDoubleErrorValue( double fVal )
+inline FormulaError GetDoubleErrorValue( double fVal )
 {
     if ( ::rtl::math::isFinite( fVal ) )
-        return 0;
+        return FormulaError::NONE;
     if ( ::rtl::math::isInf( fVal ) )
-        return errIllegalFPOperation;       // normal INF
+        return FormulaError::IllegalFPOperation;       // normal INF
     sal_uInt32 nErr = reinterpret_cast< sal_math_Double * >( &fVal)->nan_parts.fraction_lo;
     if ( nErr & 0xffff0000 )
-        return errNoValue;                  // just a normal NAN
+        return FormulaError::NoValue;                  // just a normal NAN
     if (!nErr)
         // Another NAN, e.g. -nan(0x8000000000000) from calculating with -inf
-        return errIllegalFPOperation;
+        return FormulaError::IllegalFPOperation;
     // Any other error known to us as error code.
-    return (sal_uInt16)(nErr & 0x0000ffff);
+    return (FormulaError)(nErr & 0x0000ffff);
 }
 
-} // namespace formula
-
 #endif // INCLUDED_FORMULA_ERRORCODES_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/formula/token.hxx b/include/formula/token.hxx
index e0ee120..767fa21 100644
--- a/include/formula/token.hxx
+++ b/include/formula/token.hxx
@@ -39,6 +39,7 @@ class ScJumpMatrix;
 class ScMatrix;
 struct ScComplexRefData;
 struct ScSingleRefData;
+enum class FormulaError : sal_uInt16;
 
 namespace formula
 {
@@ -161,8 +162,8 @@ public:
     virtual short*              GetJump() const;
     virtual const OUString&     GetExternal() const;
     virtual FormulaToken*       GetFAPOrigToken() const;
-    virtual sal_uInt16          GetError() const;
-    virtual void                SetError( sal_uInt16 );
+    virtual FormulaError        GetError() const;
+    virtual void                SetError( FormulaError );
 
     virtual const ScSingleRefData*  GetSingleRef() const;
     virtual ScSingleRefData*        GetSingleRef();
@@ -431,16 +432,16 @@ public:
 
 class FORMULA_DLLPUBLIC FormulaErrorToken : public FormulaToken
 {
-            sal_uInt16          nError;
+         FormulaError          nError;
 public:
-                                FormulaErrorToken( sal_uInt16 nErr ) :
+                                FormulaErrorToken( FormulaError nErr ) :
                                     FormulaToken( svError ), nError( nErr) {}
                                 FormulaErrorToken( const FormulaErrorToken& r ) :
                                     FormulaToken( r ), nError( r.nError) {}
 
     virtual FormulaToken*       Clone() const override { return new FormulaErrorToken(*this); }
-    virtual sal_uInt16          GetError() const override;
-    virtual void                SetError( sal_uInt16 nErr ) override;
+    virtual FormulaError        GetError() const override;
+    virtual void                SetError( FormulaError nErr ) override;
     virtual bool                operator==( const FormulaToken& rToken ) const override;
 };
 
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index b1d2deb..1c6ed22 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -123,7 +123,7 @@ protected:
     sal_uInt16      nLen;                   // Length of token array
     sal_uInt16      nRPN;                   // Length of RPN array
     sal_uInt16      nIndex;                 // Current step index
-    sal_uInt16      nError;                 // Error code
+    FormulaError    nError;                 // Error code
     ScRecalcMode    nMode;                  // Flags to indicate when to recalc this code
     bool            bHyperLink;             // If HYPERLINK() occurs in the formula.
     bool            mbFromRangeName;        // If this array originates from a named expression
@@ -230,11 +230,11 @@ public:
 
     FormulaToken** GetArray() const  { return pCode; }
     FormulaToken** GetCode()  const  { return pRPN; }
-    sal_uInt16    GetLen() const     { return nLen; }
-    sal_uInt16    GetCodeLen() const { return nRPN; }
-    void      Reset()            { nIndex = 0; }
-    sal_uInt16    GetCodeError() const      { return nError; }
-    void      SetCodeError( sal_uInt16 n )  { nError = n; }
+    sal_uInt16     GetLen() const     { return nLen; }
+    sal_uInt16     GetCodeLen() const { return nRPN; }
+    void           Reset()            { nIndex = 0; }
+    FormulaError   GetCodeError() const      { return nError; }
+    void      SetCodeError( FormulaError n )  { nError = n; }
     void      SetHyperLink( bool bVal ) { bHyperLink = bVal; }
     bool      IsHyperLink() const       { return bHyperLink; }
 
diff --git a/sc/inc/addincol.hxx b/sc/inc/addincol.hxx
index 09d6fc5..49d30b6 100644
--- a/sc/inc/addincol.hxx
+++ b/sc/inc/addincol.hxx
@@ -187,7 +187,7 @@ private:
     css::uno::Reference<css::uno::XInterface> xCaller;
     bool                        bValidCount;
     // result:
-    sal_uInt16                  nErrCode;
+    FormulaError                nErrCode;
     bool                        bHasString;
     double                      fValue;
     OUString                    aString;
@@ -214,7 +214,7 @@ public:
 
     void                SetResult( const css::uno::Any& rNewRes );
 
-    sal_uInt16          GetErrCode() const      { return nErrCode; }
+    FormulaError        GetErrCode() const      { return nErrCode; }
     bool                HasString() const       { return bHasString; }
     bool                HasMatrix() const       { return xMatrix.get(); }
     bool                HasVarRes() const       { return ( xVarRes.is() ); }
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 186e415..2041ce7 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -360,7 +360,7 @@ public:
     void SetValue( SCROW nRow, double fVal );
     void SetValues( SCROW nRow, const std::vector<double>& rVals );
     void SetValue( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, double fVal, bool bBroadcast = true );
-    void        SetError( SCROW nRow, const sal_uInt16 nError);
+    void        SetError( SCROW nRow, const FormulaError nError);
 
     void        GetString( SCROW nRow, OUString& rString ) const;
     double* GetValueCell( SCROW nRow );
@@ -376,7 +376,7 @@ public:
     SCSIZE      GetCellCount() const;
     sal_uInt32 GetWeightedCount() const;
     sal_uInt32 GetCodeCount() const;       // RPN-Code in formulas
-    sal_uInt16  GetErrCode( SCROW nRow ) const;
+    FormulaError  GetErrCode( SCROW nRow ) const;
 
     bool    HasStringData( SCROW nRow ) const;
     bool    HasValueData( SCROW nRow ) const;
@@ -403,7 +403,7 @@ public:
                 position broadcasted. */
     bool BroadcastBroadcasters( SCROW nRow1, SCROW nRow2, ScHint& rHint );
 
-    bool CompileErrorCells( sc::CompileFormulaContext& rCxt, sal_uInt16 nErrCode );
+    bool CompileErrorCells( sc::CompileFormulaContext& rCxt, FormulaError nErrCode );
 
     void        ResetChanged( SCROW nStartRow, SCROW nEndRow );
 
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 26be57d..8c64856 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -130,7 +130,7 @@ public:
             rtl_uString* mpDataIgnoreCase;
         } sharedstring;
         ScMatrix*    pMat;
-        sal_uInt16   nError;
+        FormulaError nError;
         sal_Unicode  cStr[ MAXSTRLEN+1 ];   // string (up to 255 characters + 0)
         short        nJump[ FORMULA_MAXJUMPCOUNT + 1 ];     // If/Chose token
     };
@@ -152,7 +152,7 @@ public:
     void SetSingleReference( const ScSingleRefData& rRef );
     void SetDoubleReference( const ScComplexRefData& rRef );
     void SetDouble( double fVal );
-    void SetErrorConstant( sal_uInt16 nErr );
+    void SetErrorConstant( FormulaError nErr );
 
     // These methods are ok to use, reference count not cleared.
     void SetName(sal_Int16 nSheet, sal_uInt16 nIndex);
@@ -304,7 +304,7 @@ private:
 
     bool   NextNewToken(bool bInArray);
 
-    virtual void SetError(sal_uInt16 nError) override;
+    virtual void SetError(FormulaError nError) override;
     sal_Int32 NextSymbol(bool bInArray);
     bool IsValue( const OUString& );
     bool IsOpCode( const OUString&, bool bInArray );
diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index 088ca7f..21f5ffc 100644
--- a/sc/inc/dociter.hxx
+++ b/sc/inc/dociter.hxx
@@ -77,7 +77,7 @@ class ScValueIterator            // walk through all values in an area
      * See if the cell at the current position is a non-empty cell. If not,
      * move to the next non-empty cell position.
      */
-    bool GetThis( double& rValue, sal_uInt16& rErr );
+    bool GetThis( double& rValue, FormulaError& rErr );
 
 public:
 
@@ -88,10 +88,10 @@ public:
     void GetCurNumFmtInfo( short& nType, sal_uLong& nIndex );
 
     /// Does NOT reset rValue if no value found!
-    bool GetFirst( double& rValue, sal_uInt16& rErr );
+    bool GetFirst( double& rValue, FormulaError& rErr );
 
     /// Does NOT reset rValue if no value found!
-    bool GetNext( double& rValue, sal_uInt16& rErr );
+    bool GetNext( double& rValue, FormulaError& rErr );
 };
 
 class ScDBQueryDataIterator
@@ -99,9 +99,9 @@ class ScDBQueryDataIterator
 public:
     struct Value
     {
-        OUString maString;
+        OUString        maString;
         double          mfValue;
-        sal_uInt16      mnError;
+        FormulaError    mnError;
         bool            mbIsNumber;
 
         Value();
@@ -466,7 +466,7 @@ public:
                                                const ScRange& rRange );
                     ~ScHorizontalValueIterator();
     /// Does NOT reset rValue if no value found!
-    bool            GetNext( double& rValue, sal_uInt16& rErr );
+    bool            GetNext( double& rValue, FormulaError& rErr );
 };
 
 //  returns all areas with non-default formatting (horizontal)
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 289d6df..979257e 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -49,6 +49,7 @@
 
 enum class SvtScriptType;
 enum class ScMF;
+enum class FormulaError : sal_uInt16;
 namespace editeng { class SvxBorderLine; }
 namespace formula { struct VectorRefArray; }
 namespace svl {
@@ -1000,7 +1001,7 @@ public:
 
     void SetValues( const ScAddress& rPos, const std::vector<double>& rVals );
 
-    void SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 nError);
+    void SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const FormulaError nError);
 
     SC_DLLPUBLIC void SetFormula(
         const ScAddress& rPos, const ScTokenArray& rArray );
@@ -1057,7 +1058,7 @@ public:
     std::shared_ptr<sc::FormulaGroupContext>& GetFormulaGroupContext();
 
     SC_DLLPUBLIC void GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& rString );
-    sal_uInt16 GetStringForFormula( const ScAddress& rPos, OUString& rString );
+    FormulaError GetStringForFormula( const ScAddress& rPos, OUString& rString );
     SC_DLLPUBLIC double GetValue( const ScAddress& rPos ) const;
     SC_DLLPUBLIC double GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
     SC_DLLPUBLIC void GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, double& rValue ) const;
@@ -1188,7 +1189,7 @@ public:
      * @return true if at least one cell is re-compiled, false if no cells are
      *         re-compiled.
      */
-    bool CompileErrorCells(sal_uInt16 nErrCode);
+    bool CompileErrorCells(FormulaError nErrCode);
 
     ScAutoNameCache* GetAutoNameCache()     { return pAutoNameCache; }
     void             SetPreviewFont( SfxItemSet* pFontSet );
@@ -1225,7 +1226,7 @@ public:
                     // if CalcFormulaTree() is currently running
     bool            IsCalculatingFormulaTree() { return bCalculatingFormulaTree; }
 
-    sal_uInt16          GetErrCode( const ScAddress& ) const;
+    FormulaError    GetErrCode( const ScAddress& ) const;
 
                     /** Shrink a range to only include data area.
 
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index cec4b2d..d30faca 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -296,13 +296,13 @@ public:
     bool            GetMatrixOrigin( ScAddress& rPos ) const;
     void            GetResultDimensions( SCSIZE& rCols, SCSIZE& rRows );
     sc::MatrixEdge  GetMatrixEdge( ScAddress& rOrgPos ) const;
-    sal_uInt16      GetErrCode();   // interpret first if necessary
-    sal_uInt16      GetRawError();  // don't interpret, just return code or result error
-    bool GetErrorOrValue( sal_uInt16& rErr, double& rVal );
+    FormulaError    GetErrCode();   // interpret first if necessary
+    FormulaError    GetRawError();  // don't interpret, just return code or result error
+    bool            GetErrorOrValue( FormulaError& rErr, double& rVal );
     sc::FormulaResultValue GetResult();
     sc::FormulaResultValue GetResult() const;
     sal_uInt8       GetMatrixFlag() const { return cMatrixFlag;}
-    ScTokenArray* GetCode() { return pCode;}
+    ScTokenArray*   GetCode() { return pCode;}
     const ScTokenArray* GetCode() const { return pCode;}
 
     void SetCode( ScTokenArray* pNew );
@@ -364,10 +364,10 @@ public:
     svl::SharedString GetResultString() const;
 
     /* Sets the shared code array to error state in addition to the cell result */
-    void SetErrCode( sal_uInt16 n );
+    void SetErrCode( FormulaError n );
 
     /* Sets just the result to error */
-    void SetResultError( sal_uInt16 n );
+    void SetResultError( FormulaError n );
 
     bool IsHyperLinkCell() const;
     EditTextObject* CreateURLObject();
diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx
index 68a08e5..0a977dc 100644
--- a/sc/inc/formularesult.hxx
+++ b/sc/inc/formularesult.hxx
@@ -33,12 +33,12 @@ struct FormulaResultValue
 
     double mfValue;
     svl::SharedString maString;
-    sal_uInt16 mnError;
+    FormulaError mnError;
 
     FormulaResultValue();
     FormulaResultValue( double fValue );
-    FormulaResultValue(const svl::SharedString& rStr );
-    FormulaResultValue( sal_uInt16 nErr );
+    FormulaResultValue( const svl::SharedString& rStr );
+    FormulaResultValue( FormulaError nErr );
 };
 
 }
@@ -71,7 +71,7 @@ class ScFormulaResult
         double          mfValue;    // double result direct for performance and memory consumption
         const formula::FormulaToken*  mpToken;    // if not, result token obtained from interpreter
     };
-    sal_uInt16              mnError;    // error code
+    FormulaError        mnError;    // error code
     bool                mbToken :1; // whether content of union is a token
     bool                mbEmpty :1; // empty cell result
     bool                mbEmptyDisplayedAsString :1;    // only if mbEmpty
@@ -154,15 +154,15 @@ public:
         one paragraph */
     bool IsMultiline() const;
 
-    bool GetErrorOrDouble( sal_uInt16& rErr, double& rVal ) const;
+    bool GetErrorOrDouble( FormulaError& rErr, double& rVal ) const;
     sc::FormulaResultValue GetResult() const;
 
     /** Get error code if set or GetCellResultType() is formula::svError or svUnknown,
         else 0. */
-    sal_uInt16 GetResultError() const;
+    FormulaError GetResultError() const;
 
     /** Set error code, don't touch token or double. */
-    void SetResultError( sal_uInt16 nErr );
+    void SetResultError( FormulaError nErr );
 
     /** Set direct double. Shouldn't be used externally except in
         ScFormulaCell for rounded CalcAsShown or SetErrCode() or
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index 0e606f8..63a7164 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -35,6 +35,7 @@ class SfxItemSet;
 class Color;
 struct ScCalcConfig;
 enum class SvtScriptType;
+enum class FormulaError : sal_uInt16;
 
 #define SC_COLLATOR_IGNORES ( \
     css::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE )
@@ -571,8 +572,8 @@ public:
     static ScFunctionMgr*   GetStarCalcFunctionMgr();
     static void             ResetFunctionList();
 
-    static OUString         GetErrorString(sal_uInt16 nErrNumber);
-    static OUString         GetLongErrorString(sal_uInt16 nErrNumber);
+    static OUString         GetErrorString(FormulaError nErrNumber);
+    static OUString         GetLongErrorString(FormulaError nErrNumber);
     static bool             EETextObjEqual( const EditTextObject* pObj1,
                                             const EditTextObject* pObj2 );
     static bool             CheckWidthInvalidate( bool& bNumFormatChanged,
@@ -676,11 +677,11 @@ SC_DLLPUBLIC    static const sal_Unicode* FindUnquoted( const sal_Unicode* pStri
 
         In any case, if rError is set 0.0 is returned.
 
-        If nStringNoValueError is errCellNoValue, that is unconditionally
+        If nStringNoValueError is FormulaError::CellNoValue, that is unconditionally
         assigned to rError and 0.0 is returned. The caller is expected to
         handle this situation. Used by the interpreter.
 
-        Usually errNoValue is passed as nStringNoValueError.
+        Usually FormulaError::NoValue is passed as nStringNoValueError.
 
         Otherwise, depending on the string conversion configuration different
         approaches are taken:
@@ -778,7 +779,7 @@ SC_DLLPUBLIC    static const sal_Unicode* FindUnquoted( const sal_Unicode* pStri
 
      */
     static double ConvertStringToValue( const OUString& rStr, const ScCalcConfig& rConfig,
-            sal_uInt16 & rError, sal_uInt16 nStringNoValueError,
+            FormulaError & rError, FormulaError nStringNoValueError,
             SvNumberFormatter* pFormatter, short & rCurFmtType );
 
 };
diff --git a/sc/inc/math.hxx b/sc/inc/math.hxx
index ecea704..c2a3b99 100644
--- a/sc/inc/math.hxx
+++ b/sc/inc/math.hxx
@@ -30,7 +30,7 @@ namespace sc {
 inline double div( const double& fNumerator, const double& fDenominator )
 {
     return (fDenominator != 0.0) ? (fNumerator / fDenominator) :
-        formula::CreateDoubleError( formula::errDivisionByZero);
+        CreateDoubleError( FormulaError::DivisionByZero);
 }
 
 /** Return fNumerator/fDenominator if fDenominator!=0 else +-Infinity if
diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index e5a6dfe..a1924de 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -119,7 +119,7 @@ public:
     ScTokenArray*   GetCode()                       { return pCode; }
     SC_DLLPUBLIC void   SetCode( ScTokenArray& );
     const ScTokenArray* GetCode() const             { return pCode; }
-    SC_DLLPUBLIC sal_uInt16 GetErrCode() const;
+    SC_DLLPUBLIC FormulaError GetErrCode() const;
     bool            HasReferences() const;
     void            AddType( Type nType );
     Type            GetType() const                 { return eType; }
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index b489968..d26961d 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -40,6 +40,7 @@
 class ScInterpreter;
 class SvNumberFormatter;
 class ScMatrixImpl;
+enum class FormulaError : sal_uInt16;
 
 namespace formula { class DoubleVectorRefToken; }
 
@@ -64,7 +65,7 @@ struct ScMatrixValue
     const svl::SharedString& GetString() const { return aStr; }
 
     /// Only valid if ScMatrix methods indicate that this is no string!
-    sal_uInt16 GetError() const { return formula::GetDoubleErrorValue( fVal); }
+    FormulaError GetError() const { return GetDoubleErrorValue(fVal); }
 
     /// Only valid if ScMatrix methods indicate that this is a boolean
     bool GetBoolean() const         { return fVal != 0.0; }
@@ -274,7 +275,7 @@ public:
 
     /// Jump sal_False without path
     virtual void PutEmptyPath( SCSIZE nC, SCSIZE nR) = 0;
-    virtual void PutError( sal_uInt16 nErrorCode, SCSIZE nC, SCSIZE nR ) = 0;
+    virtual void PutError( FormulaError nErrorCode, SCSIZE nC, SCSIZE nR ) = 0;
     virtual void PutBoolean( bool bVal, SCSIZE nC, SCSIZE nR) = 0;
 
     virtual void FillDouble( double fVal,
@@ -300,12 +301,12 @@ public:
         @ATTENTION: MUST NOT be used if the element is a string!
                     Use GetErrorIfNotString() instead if not sure.
         @returns 0 if no error, else one of err... constants */
-    virtual sal_uInt16 GetError( SCSIZE nC, SCSIZE nR) const = 0;
+    virtual FormulaError GetError( SCSIZE nC, SCSIZE nR) const = 0;
 
     /** Use in ScInterpreter to obtain the error code, if any.
         @returns 0 if no error or string element, else one of err... constants */
-    sal_uInt16 GetErrorIfNotString( SCSIZE nC, SCSIZE nR) const
-        { return IsValue( nC, nR) ? GetError( nC, nR) : 0; }
+    FormulaError GetErrorIfNotString( SCSIZE nC, SCSIZE nR) const
+        { return IsValue( nC, nR) ? GetError( nC, nR) : FormulaError::NONE; }
 
     /// @return 0.0 if empty or empty path, else value or DoubleError.
     virtual double GetDouble( SCSIZE nC, SCSIZE nR) const = 0;
@@ -493,7 +494,7 @@ public:
 
     /// Jump sal_False without path
     virtual void PutEmptyPath( SCSIZE nC, SCSIZE nR) override;
-    virtual void PutError( sal_uInt16 nErrorCode, SCSIZE nC, SCSIZE nR ) override;
+    virtual void PutError( FormulaError nErrorCode, SCSIZE nC, SCSIZE nR ) override;
     virtual void PutBoolean( bool bVal, SCSIZE nC, SCSIZE nR) override;
 
     virtual void FillDouble( double fVal,
@@ -519,7 +520,7 @@ public:
         @ATTENTION: MUST NOT be used if the element is a string!
                     Use GetErrorIfNotString() instead if not sure.
         @returns 0 if no error, else one of err... constants */
-    virtual sal_uInt16 GetError( SCSIZE nC, SCSIZE nR) const override;
+    virtual FormulaError GetError( SCSIZE nC, SCSIZE nR) const override;
 
     /// @return 0.0 if empty or empty path, else value or DoubleError.
     virtual double GetDouble( SCSIZE nC, SCSIZE nR) const override;
@@ -711,7 +712,7 @@ public:
 
     /// Jump sal_False without path
     virtual void PutEmptyPath(SCSIZE nC, SCSIZE nR) override;
-    virtual void PutError(sal_uInt16 nErrorCode, SCSIZE nC, SCSIZE nR ) override;
+    virtual void PutError(FormulaError nErrorCode, SCSIZE nC, SCSIZE nR ) override;
     virtual void PutBoolean(bool bVal, SCSIZE nC, SCSIZE nR) override;
 
     virtual void FillDouble(double fVal, SCSIZE nC1, SCSIZE nR1, SCSIZE nC2, SCSIZE nR2) override;
@@ -736,7 +737,7 @@ public:
         @ATTENTION: MUST NOT be used if the element is a string!
                     Use GetErrorIfNotString() instead if not sure.
         @returns 0 if no error, else one of err... constants */
-    virtual sal_uInt16 GetError(SCSIZE nC, SCSIZE nR) const override;
+    virtual FormulaError GetError(SCSIZE nC, SCSIZE nR) const override;
 
     /// @return 0.0 if empty or empty path, else value or DoubleError.
     virtual double GetDouble(SCSIZE nC, SCSIZE nR) const override;
diff --git a/sc/inc/simpleformulacalc.hxx b/sc/inc/simpleformulacalc.hxx
index fef4fe9..64229af 100644
--- a/sc/inc/simpleformulacalc.hxx
+++ b/sc/inc/simpleformulacalc.hxx
@@ -45,7 +45,7 @@ public:
     void Calculate();
     bool IsValue();
     bool IsMatrix();
-    sal_uInt16 GetErrCode();
+    FormulaError GetErrCode();
     double GetValue();
     svl::SharedString GetString();
     short GetFormatType() const { return mnFormatType; }
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 8e35256..d987071 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -34,6 +34,7 @@
 #include "cellvalue.hxx"
 #include <formula/types.hxx>
 #include "calcmacros.hxx"
+#include "formula/errorcodes.hxx"
 
 #include <set>
 #include <map>
@@ -362,7 +363,7 @@ public:
 
     void        SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
     void        SetValues( SCCOL nCol, SCROW nRow, const std::vector<double>& rVals );
-    void        SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError);
+    void        SetError( SCCOL nCol, SCROW nRow, FormulaError nError);
     SCSIZE      GetPatternCount( SCCOL nCol ) const;
     SCSIZE      GetPatternCount( SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const;
     bool        ReservePatternCount( SCCOL nCol, SCSIZE nReserve );
@@ -522,11 +523,11 @@ public:
     bool        HasStringCells( SCCOL nStartCol, SCROW nStartRow,
                                 SCCOL nEndCol, SCROW nEndRow ) const;
 
-    sal_uInt16      GetErrCode( const ScAddress& rPos ) const
+    FormulaError    GetErrCode( const ScAddress& rPos ) const
                     {
                         return ValidColRow(rPos.Col(),rPos.Row()) ?
                             aCol[rPos.Col()].GetErrCode( rPos.Row() ) :
-                            0;
+                            FormulaError::NONE;
                     }
 
     void        ResetChanged( const ScRange& rRange );
@@ -549,7 +550,7 @@ public:
                 position broadcasted. */
     bool BroadcastBroadcasters( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScHint& rHint );
 
-    bool CompileErrorCells( sc::CompileFormulaContext& rCxt, sal_uInt16 nErrCode );
+    bool CompileErrorCells( sc::CompileFormulaContext& rCxt, FormulaError nErrCode );
 
     void UpdateReference(
         sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc = nullptr,
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 7e74465..7153c4b 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -18,7 +18,7 @@
 #include <svx/svdoole2.hxx>
 #include <editeng/brushitem.hxx>
 #include <editeng/justifyitem.hxx>
-
+#include <formula/errorcodes.hxx>
 #include <cppunit/Asserter.h>
 #include <cppunit/AdditionalMessage.h>
 
@@ -522,7 +522,7 @@ bool isFormulaWithoutError(ScDocument& rDoc, const ScAddress& rPos)
     if (!pFC)
         return false;
 
-    return pFC->GetErrCode() == 0;
+    return pFC->GetErrCode() == FormulaError::NONE;
 }
 
 OUString toString(
diff --git a/sc/qa/unit/helper/shared_test_impl.hxx b/sc/qa/unit/helper/shared_test_impl.hxx
index 0c27481..7a27d31 100644
--- a/sc/qa/unit/helper/shared_test_impl.hxx
+++ b/sc/qa/unit/helper/shared_test_impl.hxx
@@ -14,6 +14,7 @@
 #include "conditio.hxx"
 #include "document.hxx"
 #include "formulacell.hxx"
+#include <formula/errorcodes.hxx>
 
 struct FindCondFormatByEnclosingRange
 {
@@ -259,8 +260,8 @@ void testFunctionsExcel2010_Impl( ScDocument& rDoc )
                 OString::number( rDoc.GetValue( ScAddress( 2, nRow, 0)) );
 
             ScFormulaCell* pFC = rDoc.GetFormulaCell( ScAddress( 1, nRow, 0) );
-            if ( pFC && pFC->GetErrCode() != 0 )
-                aStr += ", error code =" + OString::number( pFC->GetErrCode() );
+            if ( pFC && pFC->GetErrCode() != FormulaError::NONE )
+                aStr += ", error code =" + OString::number( (int)pFC->GetErrCode() );
 
             CPPUNIT_ASSERT_MESSAGE( OString( "Expected a formula cell without error at row " +
                     aStr ).getStr(), isFormulaWithoutError( rDoc, ScAddress( 1, nRow, 0)));
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 9adc1a0..4b53e2d 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -3364,8 +3364,8 @@ void ScFiltersTest::testVBAUserFunctionXLSM()
     CPPUNIT_ASSERT_EQUAL(OUString("=MYFUNC()"), aFormula);
 
     // Check the formula state after the load.
-    sal_uInt16 nErrCode = pFC->GetErrCode();
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0), nErrCode);
+    FormulaError nErrCode = pFC->GetErrCode();
+    CPPUNIT_ASSERT_EQUAL(0, (int)nErrCode);
 
     // Check the result.
     CPPUNIT_ASSERT_EQUAL(42.0, rDoc.GetValue(ScAddress(0,0,0)));
@@ -3409,7 +3409,7 @@ void ScFiltersTest::testErrorOnExternalReferences()
 
     ScFormulaCell* pFC = rDoc.GetFormulaCell(ScAddress(0,0,0));
     CPPUNIT_ASSERT(pFC);
-    CPPUNIT_ASSERT_EQUAL(formula::errNoName, pFC->GetErrCode());
+    CPPUNIT_ASSERT_EQUAL((int)FormulaError::NoName, (int)pFC->GetErrCode());
 
     if (!checkFormula(rDoc, ScAddress(0,0,0), "'file:///Path/To/FileA.ods'#$Sheet1.A1A"))
         CPPUNIT_FAIL("Formula changed");
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 7e8654f..0db6a1c 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -900,12 +900,12 @@ void Test::testValueIterator()
         bool bHas = false;
         size_t nCheckPos = 0;
         double fVal;
-        sal_uInt16 nErr;
+        FormulaError nErr;
         for (bHas = aIter.GetFirst(fVal, nErr); bHas; bHas = aIter.GetNext(fVal, nErr), ++nCheckPos)
         {
             CPPUNIT_ASSERT_MESSAGE("Iteration longer than expected.", nCheckPos < nCheckLen);
             CPPUNIT_ASSERT_EQUAL(aChecks[nCheckPos], fVal);
-            CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0), nErr);
+            CPPUNIT_ASSERT_EQUAL(0, (int)nErr);
         }
     }
 
@@ -5776,8 +5776,8 @@ void Test::testFormulaWizardSubformula()
     m_pDoc->SetString(ScAddress(1,2,0), "=gibberish");  // B3
 
     ScSimpleFormulaCalculator aFCell1( m_pDoc, ScAddress(0,0,0), "=B1:B3", true );
-    sal_uInt16 nErrCode = aFCell1.GetErrCode();
-    CPPUNIT_ASSERT( nErrCode == 0 || aFCell1.IsMatrix() );
+    FormulaError nErrCode = aFCell1.GetErrCode();
+    CPPUNIT_ASSERT( nErrCode == FormulaError::NONE || aFCell1.IsMatrix() );
     CPPUNIT_ASSERT_EQUAL( OUString("{1;#DIV/0!;#NAME?}"), aFCell1.GetString().getString() );
 
     m_pDoc->SetString(ScAddress(1,0,0), "=NA()");       // B1
@@ -5785,7 +5785,7 @@ void Test::testFormulaWizardSubformula()
     m_pDoc->SetString(ScAddress(1,2,0), "=1+2");        // B3
     ScSimpleFormulaCalculator aFCell2( m_pDoc, ScAddress(0,0,0), "=B1:B3", true );
     nErrCode = aFCell2.GetErrCode();
-    CPPUNIT_ASSERT( nErrCode == 0 || aFCell2.IsMatrix() );
+    CPPUNIT_ASSERT( nErrCode == FormulaError::NONE || aFCell2.IsMatrix() );
     CPPUNIT_ASSERT_EQUAL( OUString("{#N/A;2;3}"), aFCell2.GetString().getString() );
 
     m_pDoc->DeleteTab(0);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 38f15fa..c343686 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -1141,11 +1141,11 @@ void Test::testFormulaRefUpdate()
     aPos = ScAddress(2,1,0);
     ScFormulaCell* pFC = m_pDoc->GetFormulaCell(aPos);
     CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
-    CPPUNIT_ASSERT_EQUAL(formula::errNoRef, pFC->GetErrCode());
+    CPPUNIT_ASSERT_EQUAL((int)FormulaError::NoRef, (int)pFC->GetErrCode());
     aPos = ScAddress(2,2,0);
     pFC = m_pDoc->GetFormulaCell(aPos);
     CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
-    CPPUNIT_ASSERT_EQUAL(formula::errNoRef, pFC->GetErrCode());
+    CPPUNIT_ASSERT_EQUAL((int)FormulaError::NoRef, (int)pFC->GetErrCode());
 
     // Clear all and start over.
     clearRange(m_pDoc, ScRange(0,0,0,10,10,0));
@@ -1245,11 +1245,11 @@ void Test::testFormulaRefUpdate()
     // Both A4 and A5 should show #REF! errors.
     pFC = m_pDoc->GetFormulaCell(ScAddress(0,3,0));
     CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
-    CPPUNIT_ASSERT_EQUAL(formula::errNoRef, pFC->GetErrCode());
+    CPPUNIT_ASSERT_EQUAL((int)FormulaError::NoRef, (int)pFC->GetErrCode());
 
     pFC = m_pDoc->GetFormulaCell(ScAddress(0,4,0));
     CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
-    CPPUNIT_ASSERT_EQUAL(formula::errNoRef, pFC->GetErrCode());
+    CPPUNIT_ASSERT_EQUAL((int)FormulaError::NoRef, (int)pFC->GetErrCode());
 
     m_pDoc->DeleteTab(0);
 }
@@ -1862,7 +1862,7 @@ void Test::testFormulaRefUpdateInsertRows()
     rFunc.InsertCells(ScRange(0,1,0,MAXCOL,3,0), &aMark, INS_INSROWS_BEFORE, false, true);
     ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(0,5,0));
     CPPUNIT_ASSERT(pFC);
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("This formula cell should not be an error.", static_cast<sal_uInt16>(0), pFC->GetErrCode());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("This formula cell should not be an error.", 0, (int)pFC->GetErrCode());
     ASSERT_DOUBLES_EQUAL(3.0, m_pDoc->GetValue(ScAddress(0,5,0)));
 
     ASSERT_FORMULA_EQUAL(*m_pDoc, ScAddress(0,5,0), "MAX(A7:A9)", "Wrong formula!");
@@ -3547,19 +3547,19 @@ void Test::testFuncSUM()
 
     // Set #DIV/0! error to A3. A4 should also inherit this error.
     m_pDoc->SetString(ScAddress(0,2,0), "=1/0");
-    sal_uInt16 nErr = m_pDoc->GetErrCode(ScAddress(0,2,0));
+    FormulaError nErr = m_pDoc->GetErrCode(ScAddress(0,2,0));
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell should have a division by zero error.",
-                           errDivisionByZero, nErr);
+                           (int)FormulaError::DivisionByZero, (int)nErr);
     nErr = m_pDoc->GetErrCode(ScAddress(0,3,0));
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SUM should have also inherited a div-by-zero error.",
-                           errDivisionByZero, nErr);
+                           (int)FormulaError::DivisionByZero, (int)nErr);
 
     // Set #NA! to A2. A4 should now inherit this error.
     m_pDoc->SetString(ScAddress(0,1,0), "=NA()");
     nErr = m_pDoc->GetErrCode(ScAddress(0,1,0));
-    CPPUNIT_ASSERT_MESSAGE("A2 should be an error.", nErr);
+    CPPUNIT_ASSERT_MESSAGE("A2 should be an error.", nErr != FormulaError::NONE);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("A4 should have inherited the same error as A2.",
-                           nErr, m_pDoc->GetErrCode(ScAddress(0,3,0)));
+                           (int)nErr, (int)m_pDoc->GetErrCode(ScAddress(0,3,0)));
 
     m_pDoc->DeleteTab(0);
 }
@@ -3642,8 +3642,8 @@ void Test::testFuncSUMPRODUCT()
 
     // Force an error in C2 and test ForcedArray matrix error propagation.
     m_pDoc->SetString( 2, 1, 0, "=1/0");
-    sal_uInt16 nError = m_pDoc->GetErrCode(aPos);
-    CPPUNIT_ASSERT_MESSAGE("Formula result should be a propagated error", nError);
+    FormulaError nError = m_pDoc->GetErrCode(aPos);
+    CPPUNIT_ASSERT_MESSAGE("Formula result should be a propagated error", nError != FormulaError::NONE);
 
     // Test ForceArray propagation of SUMPRODUCT parameters to ABS and + operator.
     // => ABS({-3,4})*({-3,4}+{-3,4}) => {3,4}*{-6,8} => {-18,32} => 14
@@ -3715,8 +3715,8 @@ void Test::testFuncMIN()
     CPPUNIT_ASSERT_EQUAL(static_cast<SCCOL>(1), nCols);
     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), nRows);
 
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula in C1 is invalid.", static_cast<sal_uInt16>(0), m_pDoc->GetErrCode(ScAddress(2,0,0)));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula in C2 is invalid.", static_cast<sal_uInt16>(0), m_pDoc->GetErrCode(ScAddress(2,1,0)));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula in C1 is invalid.", 0, (int)m_pDoc->GetErrCode(ScAddress(2,0,0)));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Formula in C2 is invalid.", 0, (int)m_pDoc->GetErrCode(ScAddress(2,1,0)));
 
     CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(2,0,0)));
     CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(2,1,0)));
@@ -3962,8 +3962,8 @@ void Test::testFuncCHOOSE()
     m_pDoc->InsertTab(0, "Formula");
 
     m_pDoc->SetString(ScAddress(0,0,0), "=CHOOSE(B1;\"one\";\"two\";\"three\")");
-    sal_uInt16 nError = m_pDoc->GetErrCode(ScAddress(0,0,0));
-    CPPUNIT_ASSERT_MESSAGE("Formula result should be an error since B1 is still empty.", nError);
+    FormulaError nError = m_pDoc->GetErrCode(ScAddress(0,0,0));
+    CPPUNIT_ASSERT_MESSAGE("Formula result should be an error since B1 is still empty.", nError != FormulaError::NONE);
     m_pDoc->SetValue(ScAddress(1,0,0), 1.0);
     CPPUNIT_ASSERT_EQUAL(OUString("one"), m_pDoc->GetString(ScAddress(0,0,0)));
     m_pDoc->SetValue(ScAddress(1,0,0), 2.0);
@@ -3972,7 +3972,7 @@ void Test::testFuncCHOOSE()
     CPPUNIT_ASSERT_EQUAL(OUString("three"), m_pDoc->GetString(ScAddress(0,0,0)));
     m_pDoc->SetValue(ScAddress(1,0,0), 4.0);
     nError = m_pDoc->GetErrCode(ScAddress(0,0,0));
-    CPPUNIT_ASSERT_MESSAGE("Formula result should be an error due to out-of-bound input..", nError);
+    CPPUNIT_ASSERT_MESSAGE("Formula result should be an error due to out-of-bound input..", nError != FormulaError::NONE);
 
     m_pDoc->DeleteTab(0);
 }
@@ -4285,9 +4285,9 @@ void Test::testFuncLOOKUP()
     printRange(m_pDoc, ScRange(0,4,0,1,6,0), "Data range for LOOKUP.");
 
     // Values for B5:B7 should be 1, 2, and 3.
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("This formula should not have an error code.", static_cast<sal_uInt16>(0), m_pDoc->GetErrCode(ScAddress(1,4,0)));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("This formula should not have an error code.", static_cast<sal_uInt16>(0), m_pDoc->GetErrCode(ScAddress(1,5,0)));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("This formula should not have an error code.", static_cast<sal_uInt16>(0), m_pDoc->GetErrCode(ScAddress(1,6,0)));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("This formula should not have an error code.", 0, (int)m_pDoc->GetErrCode(ScAddress(1,4,0)));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("This formula should not have an error code.", 0, (int)m_pDoc->GetErrCode(ScAddress(1,5,0)));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("This formula should not have an error code.", 0, (int)m_pDoc->GetErrCode(ScAddress(1,6,0)));
 
     ASSERT_DOUBLES_EQUAL(1.0, m_pDoc->GetValue(ScAddress(1,4,0)));
     ASSERT_DOUBLES_EQUAL(2.0, m_pDoc->GetValue(ScAddress(1,5,0)));
@@ -4923,7 +4923,7 @@ void Test::testFuncINDIRECT2()
     // Check formula cell error
     ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(0,9,2));
     CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
-    CPPUNIT_ASSERT_MESSAGE("This formula cell should be an error.", pFC->GetErrCode() != 0);
+    CPPUNIT_ASSERT_MESSAGE("This formula cell should be an error.", pFC->GetErrCode() != FormulaError::NONE);
 
     m_pDoc->DeleteTab(2);
     m_pDoc->DeleteTab(1);
@@ -5620,15 +5620,15 @@ void Test::testExternalRefFunctions()
     // areas these tests may be adapted.
     m_pDoc->SetString(0, 0, 0, "=SUM('file:///extdata.fake'#Data.B1:AMJ1048575)");
     ScFormulaCell* pFC = m_pDoc->GetFormulaCell( ScAddress(0,0,0));
-    sal_uInt16 nErr = pFC->GetErrCode();
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("huge external range reference expected to yield errMatrixSize", errMatrixSize, nErr);
+    FormulaError nErr = pFC->GetErrCode();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("huge external range reference expected to yield FormulaError::MatrixSize", (int)FormulaError::MatrixSize, (int)nErr);
 
     ScMarkData aMark;
     aMark.SelectOneTable(0);
     m_pDoc->InsertMatrixFormula(0,0,0,0, aMark, "'file:///extdata.fake'#Data.B1:AMJ1048575");
     pFC = m_pDoc->GetFormulaCell( ScAddress(0,0,0));
     nErr = pFC->GetErrCode();
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("huge external range reference expected to yield errMatrixSize", errMatrixSize, nErr);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("huge external range reference expected to yield FormulaError::MatrixSize", (int)FormulaError::MatrixSize, (int)nErr);
     SCSIZE nMatCols, nMatRows;
     const ScMatrix* pMat = pFC->GetMatrix();
     CPPUNIT_ASSERT_MESSAGE("matrix expected", pMat != nullptr);
diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx
index c8aa1b3..9bf5522 100644
--- a/sc/qa/unit/ucalc_pivottable.cxx
+++ b/sc/qa/unit/ucalc_pivottable.cxx
@@ -19,6 +19,7 @@
 #include "stringutil.hxx"
 #include "dbdocfun.hxx"
 
+#include <formula/errorcodes.hxx>
 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
 #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
@@ -2304,11 +2305,10 @@ void Test::testFuncGETPIVOTDATALeafAccess()
 
     m_pDoc->CalcAll();
 
-    const sal_uInt16 nNoError = 0; // no error
     for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
     {
-        sal_uInt16 nErr = m_pDoc->GetErrCode(ScAddress(4,i,1));
-        CPPUNIT_ASSERT_EQUAL(nNoError, nErr);
+        FormulaError nErr = m_pDoc->GetErrCode(ScAddress(4,i,1));
+        CPPUNIT_ASSERT_EQUAL((sal_uInt16)FormulaError::NONE, (sal_uInt16)nErr);
         double fVal = m_pDoc->GetValue(ScAddress(4,i,1));
         CPPUNIT_ASSERT_EQUAL(aChecks[i].mfResult, fVal);
     }
diff --git a/sc/source/core/data/clipcontext.cxx b/sc/source/core/data/clipcontext.cxx
index b0ac301..16084be 100644
--- a/sc/source/core/data/clipcontext.cxx
+++ b/sc/source/core/data/clipcontext.cxx
@@ -17,6 +17,7 @@
 #include <clipparam.hxx>
 
 #include <svl/intitem.hxx>
+#include <formula/errorcodes.hxx>
 
 namespace sc {
 
@@ -203,8 +204,8 @@ void CopyFromClipContext::setSingleCell( const ScAddress& rSrcPos, const ScColum
                 // Good.
                 break;
 
-            sal_uInt16 nErr = rSrcCell.mpFormula->GetErrCode();
-            if (nErr)
+            FormulaError nErr = rSrcCell.mpFormula->GetErrCode();
+            if (nErr != FormulaError::NONE)
             {
                 // error codes are cloned with values
                 if (!bNumeric)
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 67c51a4..dfe343e 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -51,6 +51,7 @@
 #include <svl/sharedstringpool.hxx>
 #include <editeng/scripttypeitem.hxx>
 #include <editeng/fieldupdater.hxx>
+#include <formula/errorcodes.hxx>
 #include <osl/diagnose.h>
 
 #include <cstring>
@@ -1125,7 +1126,7 @@ void ScColumn::CopyStaticToDocument(
                     if (rFC.GetDirty() && pDocument->GetAutoCalc())
                         rFC.Interpret();
 
-                    if (rFC.GetErrCode())
+                    if (rFC.GetErrCode() != FormulaError::NONE)
                         // Skip cells with error.
                         break;
 
@@ -1445,8 +1446,8 @@ class CopyByCloneHandler
 
         if (bCloneValue)
         {
-            sal_uInt16 nErr = rSrcCell.GetErrCode();
-            if (nErr)
+            FormulaError nErr = rSrcCell.GetErrCode();
+            if (nErr != FormulaError::NONE)
             {
                 // error codes are cloned with values
                 ScFormulaCell* pErrCell = new ScFormulaCell(&mrDestCol.GetDoc(), aDestPos);
@@ -2875,7 +2876,7 @@ public:
     {
         // for unconditional compilation
         // bCompile=true and pCode->nError=0
-        pCell->GetCode()->SetCodeError(0);
+        pCell->GetCode()->SetCodeError(FormulaError::NONE);
         pCell->SetCompile(true);
         pCell->CompileTokenArray(mrCxt);
     }
@@ -2913,10 +2914,10 @@ class CompileErrorCellsHandler
     sc::CompileFormulaContext& mrCxt;
     ScColumn& mrColumn;
     sc::CellStoreType::iterator miPos;
-    sal_uInt16 mnErrCode;
+    FormulaError mnErrCode;
     bool mbCompiled;
 public:
-    CompileErrorCellsHandler( sc::CompileFormulaContext& rCxt, ScColumn& rColumn, sal_uInt16 nErrCode ) :
+    CompileErrorCellsHandler( sc::CompileFormulaContext& rCxt, ScColumn& rColumn, FormulaError nErrCode ) :
         mrCxt(rCxt),
         mrColumn(rColumn),
         miPos(mrColumn.GetCellStore().begin()),
@@ -2927,19 +2928,19 @@ public:
 
     void operator() (size_t nRow, ScFormulaCell* pCell)
     {
-        sal_uInt16 nCurError = pCell->GetRawError();
-        if (!nCurError)
+        FormulaError nCurError = pCell->GetRawError();
+        if (nCurError == FormulaError::NONE)
             // It's not an error cell. Skip it.
             return;
 
-        if (mnErrCode && nCurError != mnErrCode)
+        if (mnErrCode != FormulaError::NONE && nCurError != mnErrCode)
             // Error code is specified, and it doesn't match. Skip it.
             return;
 
         sc::CellStoreType::position_type aPos = mrColumn.GetCellStore().position(miPos, nRow);
         miPos = aPos.first;
         sc::SharedFormulaUtil::unshareFormulaCell(aPos, *pCell);
-        pCell->GetCode()->SetCodeError(0);
+        pCell->GetCode()->SetCodeError(FormulaError::NONE);
         OUString aFormula = pCell->GetFormula(mrCxt);
         pCell->Compile(mrCxt, aFormula);
         ScColumn::JoinNewFormulaCell(aPos, *pCell);
@@ -3456,7 +3457,7 @@ void ScColumn::CompileXML( sc::CompileFormulaContext& rCxt, ScProgress& rProgres
     RegroupFormulaCells();
 }
 
-bool ScColumn::CompileErrorCells( sc::CompileFormulaContext& rCxt, sal_uInt16 nErrCode )
+bool ScColumn::CompileErrorCells( sc::CompileFormulaContext& rCxt, FormulaError nErrCode )
 {
     CompileErrorCellsHandler aHdl(rCxt, *this, nErrCode);
     sc::ProcessFormula(maCells, aHdl);
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 37d8ccd..6003565 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2224,14 +2224,14 @@ public:
                         continue;
                     }
 
-                    sal_uInt16 nErr;
+                    FormulaError nErr;
                     double fVal;
                     if (rCell.GetErrorOrValue(nErr, fVal))
                     {
                         ScAddress aAdr(mnCol, nThisRow, mnTab);
 
-                        if (nErr)
-                            fVal = formula::CreateDoubleError(nErr);
+                        if (nErr != FormulaError::NONE)
+                            fVal = CreateDoubleError(nErr);
 
                         if (!aBucket.maNumVals.empty() && nThisRow == nPrevRow + 1)
                         {
@@ -2362,12 +2362,12 @@ bool appendToBlock(
 
                     sc::FormulaResultValue aRes = rFC.GetResult();
 
-                    if (aRes.meType == sc::FormulaResultValue::Invalid || aRes.mnError)
+                    if (aRes.meType == sc::FormulaResultValue::Invalid || aRes.mnError != FormulaError::NONE)
                     {
-                        if (aRes.mnError == formula::errCircularReference)
+                        if (aRes.mnError == FormulaError::CircularReference)
                         {
                             // This cell needs to be recalculated on next visit.
-                            rFC.SetErrCode(0);
+                            rFC.SetErrCode(FormulaError::NONE);
                             rFC.SetDirtyVar();
                         }
                         return false;
@@ -2483,12 +2483,12 @@ copyFirstFormulaBlock(
     {
         ScFormulaCell& rFC = **it;
         sc::FormulaResultValue aRes = rFC.GetResult();
-        if (aRes.meType == sc::FormulaResultValue::Invalid || aRes.mnError)
+        if (aRes.meType == sc::FormulaResultValue::Invalid || aRes.mnError != FormulaError::NONE)
         {
-            if (aRes.mnError == formula::errCircularReference)
+            if (aRes.mnError == FormulaError::CircularReference)
             {
                 // This cell needs to be recalculated on next visit.
-                rFC.SetErrCode(0);
+                rFC.SetErrCode(FormulaError::NONE);
                 rFC.SetDirtyVar();
             }
             return nullptr;
@@ -2730,8 +2730,8 @@ void ScColumn::SetFormulaResults( SCROW nRow, const double* pResults, size_t nLe
     for (; pResults != pResEnd; ++pResults, ++itCell)
     {
         ScFormulaCell& rCell = **itCell;
-        sal_uInt16 nErr = formula::GetDoubleErrorValue(*pResults);
-        if (nErr != 0)
+        FormulaError nErr = GetDoubleErrorValue(*pResults);
+        if (nErr != FormulaError::NONE)
             rCell.SetResultError(nErr);
         else
             rCell.SetResultDouble(*pResults);
@@ -3151,7 +3151,7 @@ public:
         if (mrData.eFunc != SUBTOTAL_FUNC_CNT2) // it doesn't interest us
         {
 
-            if (pCell->GetErrCode())
+            if (pCell->GetErrCode() != FormulaError::NONE)
             {
                 if (mrData.eFunc != SUBTOTAL_FUNC_CNT) // simply remove from count
                     mrData.bError = true;
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 27abbbf..89aa5e0 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -936,8 +936,8 @@ public:
                         // Always just copy the original row to the Undo Documen;
                         // do not create Value/string cells from formulas
 
-                        sal_uInt16 nErr = rSrcCell.GetErrCode();
-                        if (nErr)
+                        FormulaError nErr = rSrcCell.GetErrCode();
+                        if (nErr != FormulaError::NONE)
                         {
                             // error codes are cloned with values
                             if (bNumeric)
@@ -1190,7 +1190,7 @@ class MixDataHandler
             ScAddress aPos(mrDestColumn.GetCol(), nDestRow, mrDestColumn.GetTab());
 
             ScFormulaCell* pFC = new ScFormulaCell(&mrDestColumn.GetDoc(), aPos);
-            pFC->SetErrCode(errNoValue);
+            pFC->SetErrCode(FormulaError::NoValue);
 
             miNewCellsPos = maNewCells.set(miNewCellsPos, nDestRow-mnRowOffset, pFC);
         }
@@ -1998,8 +1998,8 @@ class FilterEntriesHandler
             case CELLTYPE_FORMULA:
             {
                 ScFormulaCell* pFC = rCell.mpFormula;
-                sal_uInt16 nErr = pFC->GetErrCode();
-                if (nErr)
+                FormulaError nErr = pFC->GetErrCode();
+                if (nErr != FormulaError::NONE)
                 {
                     // Error cell is evaluated as string (for now).
                     OUString aErr = ScGlobal::GetErrorString(nErr);
@@ -2365,7 +2365,7 @@ void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow )
     aFunc.commitCells(*this);
 }
 
-void ScColumn::SetError( SCROW nRow, const sal_uInt16 nError)
+void ScColumn::SetError( SCROW nRow, const FormulaError nError)
 {
     if (!ValidRow(nRow))
         return;
@@ -2605,15 +2605,15 @@ SCSIZE ScColumn::GetCellCount() const
     return aFunc.getCount();
 }
 
-sal_uInt16 ScColumn::GetErrCode( SCROW nRow ) const
+FormulaError ScColumn::GetErrCode( SCROW nRow ) const
 {
     std::pair<sc::CellStoreType::const_iterator,size_t> aPos = maCells.position(nRow);
     sc::CellStoreType::const_iterator it = aPos.first;
     if (it == maCells.end())
-        return 0;
+        return FormulaError::NONE;
 
     if (it->type != sc::element_type_formula)
-        return 0;
+        return FormulaError::NONE;
 
     const ScFormulaCell* p = sc::formula_block::at(*it->data, aPos.second);
     return const_cast<ScFormulaCell*>(p)->GetErrCode();
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 2a6b48a..c5d712c 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -41,6 +41,7 @@
 #include "editutil.hxx"
 #include "tokenarray.hxx"
 #include "refupdatecontext.hxx"
+#include <formula/errorcodes.hxx>
 #include <svl/sharedstring.hxx>
 #include <svl/sharedstringpool.hxx>
 #include <memory>
@@ -1037,7 +1038,7 @@ bool ScConditionEntry::IsError( const ScAddress& rPos ) const
 
     if (rCell.meType == CELLTYPE_FORMULA)
     {
-        if (rCell.mpFormula->GetErrCode())
+        if (rCell.mpFormula->GetErrCode() != FormulaError::NONE)
             return true;
     }
 
diff --git a/sc/source/core/data/dbdocutl.cxx b/sc/source/core/data/dbdocutl.cxx
index 6e681f6..60a7610 100644
--- a/sc/source/core/data/dbdocutl.cxx
+++ b/sc/source/core/data/dbdocutl.cxx
@@ -157,7 +157,7 @@ void ScDatabaseDocUtil::PutData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB
         pDoc->SetEmptyCell(aPos);
     else if (bError)
     {
-        pDoc->SetError( nCol, nRow, nTab, formula::NOTAVAILABLE );
+        pDoc->SetError( nCol, nRow, nTab, FormulaError::NotAvailable );
     }
     else if (bValue)
     {
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index b9bc4db..ed39123 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -151,7 +151,7 @@ void ScValueIterator::SetPos(size_t nPos)
     maCurPos = mpCells->position(maCurPos.first, nPos);
 }
 
-bool ScValueIterator::GetThis(double& rValue, sal_uInt16& rErr)
+bool ScValueIterator::GetThis(double& rValue, FormulaError& rErr)
 {
     while (true)
     {
@@ -175,7 +175,7 @@ bool ScValueIterator::GetThis(double& rValue, sal_uInt16& rErr)
                     ++mnTab;
                     if (mnTab > maEndPos.Tab())
                     {
-                        rErr = 0;
+                        rErr = FormulaError::NONE;
                         return false; // Over and out
                     }
                 }
@@ -205,7 +205,7 @@ bool ScValueIterator::GetThis(double& rValue, sal_uInt16& rErr)
             {
                 bNumValid = false;
                 rValue = sc::numeric_block::at(*maCurPos.first->data, maCurPos.second);
-                rErr = 0;
+                rErr = FormulaError::NONE;
                 if (bCalcAsShown)
                 {
                     ScAttrArray_IterGetNumberFormat(nNumFormat, pAttrArray,
@@ -227,7 +227,7 @@ bool ScValueIterator::GetThis(double& rValue, sal_uInt16& rErr)
 
                 if (rCell.GetErrorOrValue(rErr, rValue))
                 {
-                    if ( rErr && ( mnSubTotalFlags & SUBTOTAL_IGN_ERR_VAL ) )
+                    if ( rErr != FormulaError::NONE && ( mnSubTotalFlags & SUBTOTAL_IGN_ERR_VAL ) )
                     {
                         IncPos();
                         break;
@@ -249,7 +249,7 @@ bool ScValueIterator::GetThis(double& rValue, sal_uInt16& rErr)
             {
                 if (bTextAsZero)
                 {
-                    rErr = 0;
+                    rErr = FormulaError::NONE;
                     rValue = 0.0;
                     nNumFmtType = css::util::NumberFormat::NUMBER;
                     nNumFmtIndex = 0;
@@ -282,7 +282,7 @@ void ScValueIterator::GetCurNumFmtInfo( short& nType, sal_uLong& nIndex )
     nIndex = nNumFmtIndex;
 }
 
-bool ScValueIterator::GetFirst(double& rValue, sal_uInt16& rErr)
+bool ScValueIterator::GetFirst(double& rValue, FormulaError& rErr)
 {
     mnCol = maStartPos.Col();
     mnTab = maStartPos.Tab();
@@ -300,7 +300,7 @@ bool ScValueIterator::GetFirst(double& rValue, sal_uInt16& rErr)
     return GetThis(rValue, rErr);
 }
 
-bool ScValueIterator::GetNext(double& rValue, sal_uInt16& rErr)
+bool ScValueIterator::GetNext(double& rValue, FormulaError& rErr)
 {
     IncPos();
     return GetThis(rValue, rErr);
@@ -388,7 +388,7 @@ bool ScDBQueryDataIterator::DataAccessInternal::getCurrent(Value& rValue)
         if (maCurPos.first == mpCells->end() || nRow > mpParam->nRow2)
         {
             // Bottom of the range reached. Bail out.
-            rValue.mnError = 0;
+            rValue.mnError = FormulaError::NONE;
             return false;
         }
 
@@ -426,7 +426,7 @@ bool ScDBQueryDataIterator::DataAccessInternal::getCurrent(Value& rValue)
                     }
                     nNumFmtType = css::util::NumberFormat::NUMBER;
                     nNumFmtIndex = 0;
-                    rValue.mnError = 0;
+                    rValue.mnError = FormulaError::NONE;
                     return true; // Found it!
                 }
 
@@ -461,7 +461,7 @@ bool ScDBQueryDataIterator::DataAccessInternal::getCurrent(Value& rValue)
                     {
                         rValue.maString = aCell.getString(mpDoc);
                         rValue.mfValue = 0.0;
-                        rValue.mnError = 0;
+                        rValue.mnError = FormulaError::NONE;
                         rValue.mbIsNumber = false;
                         return true;
                     }
@@ -554,7 +554,7 @@ bool ScDBQueryDataIterator::DataAccessMatrix::getCurrent(Value& rValue)
             rValue.maString = rMat.GetString(mpParam->mnField, mnCurRow).getString();
             rValue.mfValue = rMat.GetDouble(mpParam->mnField, mnCurRow);
             rValue.mbIsNumber = !bIsStrVal;
-            rValue.mnError = 0;
+            rValue.mnError = FormulaError::NONE;
             return true;
         }
     }
@@ -748,7 +748,7 @@ bool ScDBQueryDataIterator::DataAccessMatrix::isValidQuery(SCROW nRow, const ScM
 }
 
 ScDBQueryDataIterator::Value::Value() :
-    mnError(0), mbIsNumber(true)
+    mnError(FormulaError::NONE), mbIsNumber(true)
 {
     ::rtl::math::setNan(&mfValue);
 }
@@ -965,7 +965,7 @@ bool ScCellIterator::getCurrent()
                 ScFormulaCell* pCell = sc::formula_block::at(*maCurColPos.first->data, maCurColPos.second);
                 // Skip formula cells with Subtotal formulae or errors, depending on mnSubTotalFlags
                 if ( ( ( mnSubTotalFlags & SUBTOTAL_IGN_NESTED_ST_AG ) && pCell->IsSubTotal() ) ||
-                     ( ( mnSubTotalFlags & SUBTOTAL_IGN_ERR_VAL ) && pCell->GetErrCode() ) )
+                     ( ( mnSubTotalFlags & SUBTOTAL_IGN_ERR_VAL ) && pCell->GetErrCode() != FormulaError::NONE ) )
                 {
                     incPos();
                     continue;
@@ -2204,7 +2204,7 @@ ScHorizontalValueIterator::~ScHorizontalValueIterator()
     delete pCellIter;
 }
 
-bool ScHorizontalValueIterator::GetNext( double& rValue, sal_uInt16& rErr )
+bool ScHorizontalValueIterator::GetNext( double& rValue, FormulaError& rErr )
 {
     bool bFound = false;
     while ( !bFound )
@@ -2225,7 +2225,7 @@ bool ScHorizontalValueIterator::GetNext( double& rValue, sal_uInt16& rErr )
             case CELLTYPE_VALUE:
                 {
                     rValue = pCell->mfValue;
-                    rErr = 0;
+                    rErr = FormulaError::NONE;
                     if ( bCalcAsShown )
                     {
                         ScColumn* pCol = &pDoc->maTabs[nCurTab]->aCol[nCurCol];
@@ -2239,7 +2239,7 @@ bool ScHorizontalValueIterator::GetNext( double& rValue, sal_uInt16& rErr )
             case CELLTYPE_FORMULA:
                 {
                     rErr = pCell->mpFormula->GetErrCode();
-                    if (rErr || pCell->mpFormula->IsValue())
+                    if (rErr != FormulaError::NONE || pCell->mpFormula->IsValue())
                     {
                         rValue = pCell->mpFormula->GetValue();
                         bFound = true;
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 1de3620..534a788 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1095,7 +1095,7 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
     return nRetVal;
 }
 
-void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 nError)
+void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const FormulaError nError)
 {
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
         if (maTabs[nTab])
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index d2dcdb2..c503b2f 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -110,7 +110,7 @@ bool ScDocument::Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab,
             fBestX = fXPrev = fSaveVal;
 
             pFormula->Interpret();
-            bool bError = ( pFormula->GetErrCode() != 0 );
+            bool bError = ( pFormula->GetErrCode() != FormulaError::NONE );
             // bError always corresponds with fF
 
             fFPrev = pFormula->GetValue() - fTargetVal;
@@ -132,7 +132,7 @@ bool ScDocument::Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab,
                 *pVCell = fX;
                 SetDirty( aVRange, false );
                 pFormula->Interpret();
-                bError = ( pFormula->GetErrCode() != 0 );
+                bError = ( pFormula->GetErrCode() != FormulaError::NONE );
                 fF = pFormula->GetValue() - fTargetVal;
 
                 if ( fF == fFPrev && !bError )
@@ -166,7 +166,7 @@ bool ScDocument::Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab,
                             *pVCell = fHorX;
                             SetDirty( aVRange, false );
                             pFormula->Interpret();
-                            bHorMoveError = ( pFormula->GetErrCode() != 0 );
+                            bHorMoveError = ( pFormula->GetErrCode() != FormulaError::NONE );
                             if ( bHorMoveError )
                                 break;
 
@@ -243,12 +243,12 @@ bool ScDocument::Solver(SCCOL nFCol, SCROW nFRow, SCTAB nFTab,
             pFormula->Interpret();
             if ( !bDoneIteration )
             {
-                SetError( nVCol, nVRow, nVTab, NOTAVAILABLE );
+                SetError( nVCol, nVRow, nVTab, FormulaError::NotAvailable );
             }
         }
         else
         {
-            SetError( nVCol, nVRow, nVTab, NOTAVAILABLE );
+            SetError( nVCol, nVRow, nVTab, FormulaError::NotAvailable );
         }
     }
     return bRet;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 2d698ac..adcf0c9 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3498,7 +3498,7 @@ void ScDocument::GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& r
         rString.clear();
 }
 
-sal_uInt16 ScDocument::GetStringForFormula( const ScAddress& rPos, OUString& rString )
+FormulaError ScDocument::GetStringForFormula( const ScAddress& rPos, OUString& rString )
 {
     // Used in formulas (add-in parameters etc), so it must use the same semantics as
     // ScInterpreter::GetCellString: always format values as numbers.
@@ -3508,10 +3508,10 @@ sal_uInt16 ScDocument::GetStringForFormula( const ScAddress& rPos, OUString& rSt
     if (aCell.isEmpty())
     {
         rString = EMPTY_OUSTRING;
-        return 0;
+        return FormulaError::NONE;
     }
 
-    sal_uInt16 nErr = 0;
+    FormulaError nErr = FormulaError::NONE;
     OUString aStr;
     SvNumberFormatter* pFormatter = GetFormatTable();
     switch (aCell.meType)
@@ -3948,7 +3948,7 @@ void ScDocument::CompileXML()
     SetAutoCalc( bOldAutoCalc );
 }
 
-bool ScDocument::CompileErrorCells(sal_uInt16 nErrCode)
+bool ScDocument::CompileErrorCells(FormulaError nErrCode)
 {
     bool bCompiled = false;
     sc::CompileFormulaContext aCxt(this);
@@ -4000,12 +4000,12 @@ void ScDocument::CalcAfterLoad( bool bStartListening )
     }
 }
 
-sal_uInt16 ScDocument::GetErrCode( const ScAddress& rPos ) const
+FormulaError ScDocument::GetErrCode( const ScAddress& rPos ) const
 {
     SCTAB nTab = rPos.Tab();
     if ( nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
         return maTabs[nTab]->GetErrCode( rPos );
-    return 0;
+    return FormulaError::NONE;
 }
 
 void ScDocument::ResetChanged( const ScRange& rRange )
diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index 85de538..25a500c 100644
--- a/sc/source/core/data/dpcache.cxx
+++ b/sc/source/core/data/dpcache.cxx
@@ -33,6 +33,7 @@
 #include <rtl/math.hxx>
 #include <unotools/textsearch.hxx>
 #include <unotools/localedatawrapper.hxx>
+#include <formula/errorcodes.hxx>
 #include <svl/zforlist.hxx>
 #include <o3tl/make_unique.hxx>
 
@@ -129,7 +130,7 @@ void initFromCell(
 
     ScAddress aPos(nCol, nRow, nTab);
 
-    if (pDoc->GetErrCode(aPos))
+    if (pDoc->GetErrCode(aPos) != FormulaError::NONE)
     {
         rData.SetErrorString(rCache.InternString(aDocStr));
     }
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index 5d4550d..390aaf6 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -751,7 +751,7 @@ void ScDPOutput::DataCell( SCCOL nCol, SCROW nRow, SCTAB nTab, const sheet::Data
     long nFlags = rData.Flags;
     if ( nFlags & sheet::DataResultFlags::ERROR )
     {
-        pDoc->SetError( nCol, nRow, nTab, formula::errNoValue );
+        pDoc->SetError( nCol, nRow, nTab, FormulaError::NoValue );
     }
     else if ( nFlags & sheet::DataResultFlags::HASDATA )
     {
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 322f0d5..cb4bb4d 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -557,7 +557,7 @@ void ScFormulaCellGroup::compileCode(
     if (!mpCode)
         return;
 
-    if (mpCode->GetLen() && !mpCode->GetCodeError() && !mpCode->GetCodeLen())
+    if (mpCode->GetLen() && mpCode->GetCodeError() == FormulaError::NONE && !mpCode->GetCodeLen())
     {
         ScCompiler aComp(&rDoc, rPos, *mpCode);
         aComp.SetGrammar(eGram);
@@ -700,7 +700,7 @@ ScFormulaCell::ScFormulaCell(
     assert(pArray); // Never pass a NULL pointer here.
 
     // Generate RPN token array.
-    if (pCode->GetLen() && !pCode->GetCodeError() && !pCode->GetCodeLen())
+    if (pCode->GetLen() && pCode->GetCodeError() == FormulaError::NONE && !pCode->GetCodeLen())
     {
         ScCompiler aComp( pDocument, aPos, *pCode);
         aComp.SetGrammar(eTempGrammar);
@@ -750,7 +750,7 @@ ScFormulaCell::ScFormulaCell(
     SAL_INFO( "sc.core.formulacell", "ScFormulaCell ctor this " << this);
 
     // RPN array generation
-    if( pCode->GetLen() && !pCode->GetCodeError() && !pCode->GetCodeLen() )
+    if( pCode->GetLen() && pCode->GetCodeError() == FormulaError::NONE && !pCode->GetCodeLen() )
     {
         ScCompiler aComp( pDocument, aPos, *pCode);
         aComp.SetGrammar(eTempGrammar);
@@ -838,9 +838,9 @@ ScFormulaCell::ScFormulaCell(const ScFormulaCell& rCell, ScDocument& rDoc, const
     //  set back any errors and recompile
     //  not in the Clipboard - it must keep the received error flag
     //  Special Length=0: as bad cells are generated, then they are also retained
-    if ( pCode->GetCodeError() && !pDocument->IsClipboard() && pCode->GetLen() )
+    if ( pCode->GetCodeError() != FormulaError::NONE && !pDocument->IsClipboard() && pCode->GetLen() )
     {
-        pCode->SetCodeError( 0 );
+        pCode->SetCodeError( FormulaError::NONE );
         bCompile = true;
     }
     // Compile ColRowNames on URM_MOVE/URM_COPY _after_ UpdateReference !
@@ -975,7 +975,7 @@ ScFormulaVectorState ScFormulaCell::GetVectorState() const
 void ScFormulaCell::GetFormula( OUStringBuffer& rBuffer,
                                 const FormulaGrammar::Grammar eGrammar ) const
 {
-    if( pCode->GetCodeError() && !pCode->GetLen() )
+    if( pCode->GetCodeError() != FormulaError::NONE && !pCode->GetLen() )
     {
         rBuffer = OUStringBuffer( ScGlobal::GetErrorString( pCode->GetCodeError()));
         return;
@@ -1039,7 +1039,7 @@ void ScFormulaCell::GetFormula( OUString& rFormula, const FormulaGrammar::Gramma
 OUString ScFormulaCell::GetFormula( sc::CompileFormulaContext& rCxt ) const
 {
     OUStringBuffer aBuf;
-    if (pCode->GetCodeError() && !pCode->GetLen())
+    if (pCode->GetCodeError() != FormulaError::NONE && !pCode->GetLen())
     {
         aBuf = OUStringBuffer( ScGlobal::GetErrorString( pCode->GetCodeError()));
         return aBuf.makeStringAndClear();
@@ -1097,7 +1097,7 @@ void ScFormulaCell::GetResultDimensions( SCSIZE& rCols, SCSIZE& rRows )
     MaybeInterpret();
 
     const ScMatrix* pMat = nullptr;
-    if (!pCode->GetCodeError() && aResult.GetType() == svMatrixCell &&
+    if (pCode->GetCodeError() == FormulaError::NONE && aResult.GetType() == svMatrixCell &&
             ((pMat = aResult.GetToken().get()->GetMatrix()) != nullptr))
         pMat->GetDimensions( rCols, rRows );
     else
@@ -1136,7 +1136,7 @@ void ScFormulaCell::Compile( const OUString& rFormula, bool bNoListening,
     aComp.SetGrammar(eGrammar);
     pCode = aComp.CompileString( rFormula );
     delete pCodeOld;
-    if( !pCode->GetCodeError() )
+    if( pCode->GetCodeError() == FormulaError::NONE )
     {
         if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() && rFormula == aResult.GetHybridFormula() )
         {   // not recursive CompileTokenArray/Compile/CompileTokenArray
@@ -1170,7 +1170,7 @@ void ScFormulaCell::Compile(
     ScCompiler aComp(rCxt, aPos);
     pCode = aComp.CompileString( rFormula );
     delete pCodeOld;
-    if( !pCode->GetCodeError() )
+    if( pCode->GetCodeError() == FormulaError::NONE )
     {
         if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() && rFormula == aResult.GetHybridFormula() )
         {   // not recursive CompileTokenArray/Compile/CompileTokenArray
@@ -1196,7 +1196,7 @@ void ScFormulaCell::CompileTokenArray( bool bNoListening )
     {
         Compile( aResult.GetHybridFormula(), bNoListening, eTempGrammar);
     }
-    else if( bCompile && !pDocument->IsClipOrUndo() && !pCode->GetCodeError() )
+    else if( bCompile && !pDocument->IsClipOrUndo() && pCode->GetCodeError() == FormulaError::NONE )
     {
         // RPN length may get changed
         bool bWasInFormulaTree = pDocument->IsInFormulaTree( this );
@@ -1212,7 +1212,7 @@ void ScFormulaCell::CompileTokenArray( bool bNoListening )
         ScCompiler aComp(pDocument, aPos, *pCode);
         aComp.SetGrammar(pDocument->GetGrammar());
         bSubTotal = aComp.CompileTokenArray();
-        if( !pCode->GetCodeError() )
+        if( pCode->GetCodeError() == FormulaError::NONE )
         {
             nFormatType = aComp.GetNumFormatType();
             bChanged = true;
@@ -1237,7 +1237,7 @@ void ScFormulaCell::CompileTokenArray( sc::CompileFormulaContext& rCxt, bool bNo
         rCxt.setGrammar(eTempGrammar);
         Compile(rCxt, aResult.GetHybridFormula(), bNoListening);
     }
-    else if( bCompile && !pDocument->IsClipOrUndo() && !pCode->GetCodeError() )
+    else if( bCompile && !pDocument->IsClipOrUndo() && pCode->GetCodeError() == FormulaError::NONE)
     {
         // RPN length may get changed
         bool bWasInFormulaTree = pDocument->IsInFormulaTree( this );
@@ -1252,7 +1252,7 @@ void ScFormulaCell::CompileTokenArray( sc::CompileFormulaContext& rCxt, bool bNo
             EndListeningTo( pDocument );
         ScCompiler aComp(rCxt, aPos, *pCode);
         bSubTotal = aComp.CompileTokenArray();
-        if( !pCode->GetCodeError() )
+        if( pCode->GetCodeError() == FormulaError::NONE )
         {
             nFormatType = aComp.GetNumFormatType();
             bChanged = true;
@@ -1345,7 +1345,7 @@ void ScFormulaCell::CompileXML( sc::CompileFormulaContext& rCxt, ScProgress& rPr
         pCode = aComp.CompileString( aFormula, aFormulaNmsp );
         delete pCodeOld;
 
-        if( !pCode->GetCodeError() )
+        if( pCode->GetCodeError() == FormulaError::NONE )
         {
             if ( !pCode->GetLen() )
             {
@@ -1355,7 +1355,7 @@ void ScFormulaCell::CompileXML( sc::CompileFormulaContext& rCxt, ScProgress& rPr
                     pCode->AddBad( aFormula );
             }
             bSubTotal = aComp.CompileTokenArray();
-            if( !pCode->GetCodeError() )
+            if( pCode->GetCodeError() == FormulaError::NONE )
             {
                 nFormatType = aComp.GetNumFormatType();
                 bChanged = true;
@@ -1402,7 +1402,7 @@ void ScFormulaCell::CalcAfterLoad( sc::CompileFormulaContext& rCxt, bool bStartL
         bNewCompiled = true;
     }
     // The RPN array is not created when a Calc 3.0-Doc has been read as the Range Names exist until now.
-    if( pCode->GetLen() && !pCode->GetCodeLen() && !pCode->GetCodeError() )
+    if( pCode->GetLen() && !pCode->GetCodeLen() && pCode->GetCodeError() == FormulaError::NONE )
     {
         ScCompiler aComp(rCxt, aPos, *pCode);
         bSubTotal = aComp.CompileTokenArray();
@@ -1421,7 +1421,7 @@ void ScFormulaCell::CalcAfterLoad( sc::CompileFormulaContext& rCxt, bool bStartL
     if ( aResult.IsValue() && !::rtl::math::isFinite( aResult.GetDouble() ) )
     {
         OSL_FAIL("Formula cell INFINITY!!! Where does this document come from?");
-        aResult.SetResultError( errIllegalFPOperation );
+        aResult.SetResultError( FormulaError::IllegalFPOperation );
         bDirty = true;
     }
 
@@ -1436,7 +1436,7 @@ void ScFormulaCell::CalcAfterLoad( sc::CompileFormulaContext& rCxt, bool bStartL
 
     // Do the cells need to be calculated? After Load cells can contain an error code, and then start
     // the listener and Recalculate (if needed) if not ScRecalcMode::NORMAL
-    if( !bNewCompiled || !pCode->GetCodeError() )
+    if( !bNewCompiled || pCode->GetCodeError() == FormulaError::NONE )
     {
         if (bStartListening)
             StartListeningTo(pDocument);
@@ -1505,12 +1505,12 @@ void ScFormulaCell::Interpret()
     {
         if (!pDocument->GetDocOptions().IsIter())
         {
-            aResult.SetResultError( errCircularReference );
+            aResult.SetResultError( FormulaError::CircularReference );
             return;
         }
 
-        if (aResult.GetResultError() == errCircularReference)
-            aResult.SetResultError( 0 );
+        if (aResult.GetResultError() == FormulaError::CircularReference)
+            aResult.SetResultError( FormulaError::NONE );
 
         // Start or add to iteration list.
         if (!pDocument->GetRecursionHelper().IsDoingIteration() ||
@@ -1684,7 +1684,7 @@ void ScFormulaCell::Interpret()
                             // circular dependency don't, no matter whether
                             // single cells did.
                             pIterCell->ResetDirty();
-                            pIterCell->aResult.SetResultError( errNoConvergence);
+                            pIterCell->aResult.SetResultError( FormulaError::NoConvergence);
                             pIterCell->bChanged = true;
                         }
                     }
@@ -1750,7 +1750,7 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
 {
     RecursionCounter aRecursionCounter( pDocument->GetRecursionHelper(), this);
     nSeenInIteration = pDocument->GetRecursionHelper().GetIteration();
-    if( !pCode->GetCodeLen() && !pCode->GetCodeError() )
+    if( !pCode->GetCodeLen() && pCode->GetCodeError() == FormulaError::NONE )
     {
         // #i11719# no RPN and no error and no token code but result string present
         // => interpretation of this cell during name-compilation and unknown names
@@ -1763,7 +1763,7 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
         // condition further down.
         if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() )
         {
-            pCode->SetCodeError( errNoCode );
+            pCode->SetCodeError( FormulaError::NoCode );
             // This is worth an assertion; if encountered in daily work
             // documents we might need another solution. Or just confirm correctness.
             OSL_FAIL( "ScFormulaCell::Interpret: no RPN, no error, no token, but hybrid formula string" );
@@ -1791,20 +1791,21 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
         pDocument->IncInterpretLevel();
         ScInterpreter* p = new ScInterpreter( this, pDocument, aPos, *pCode );
         StackCleaner aStackCleaner( pDocument, p);
-        sal_uInt16 nOldErrCode = aResult.GetResultError();
+        FormulaError nOldErrCode = aResult.GetResultError();
         if ( nSeenInIteration == 0 )
         {   // Only the first time
             // With bChanged=false, if a newly compiled cell has a result of
             // 0.0, no change is detected and the cell will not be repainted.
             // bChanged = false;
-            aResult.SetResultError( 0 );
+            aResult.SetResultError( FormulaError::NONE );
         }
 
         switch ( aResult.GetResultError() )
         {
-            case errCircularReference :     // will be determined again if so
-                aResult.SetResultError( 0 );
+            case FormulaError::CircularReference :     // will be determined again if so

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list