silnrsi / graphite

Graphite is a "smart font" system developed specifically to handle the complexities of lesser-known languages of the world.
http://graphite.sil.org/
Other
146 stars 44 forks source link

Graphite Fails to Compile in recent Electronite version 22 - arithmetic between different enumeration types ('status_t' and 'graphite2::errors') is deprecated #78

Closed PhotoNomad0 closed 1 year ago

PhotoNomad0 commented 1 year ago

Electronite is a fork of Electron that adds Graphite support. And starting with Electron v22.0.0 (https://github.com/unfoldingWord/electronite/tree/electronite-v22.0.0-beta), graphite fails to compile in the Electron Build environment. There are three lines in:

../../third_party/graphite/graphite2/src/Pass.cpp:197:92: error: arithmetic between different enumeration types ('status_t' and 'graphite2::errors') is deprecated [-Werror,-Wdeprecated-enum-enum-conversion]

It appears that starting in Electron v22, the build environment has changed so that this has been escalated from a build warning to an error.

Found this article addressing the issue: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5054?view=msvc-170

Created a patch to handle this (as well as the std::iterator deprecated error mentioned in https://github.com/silnrsi/graphite/issues/76):

diff --git a/src/GlyphCache.cpp b/src/GlyphCache.cpp
index 282bdc18..336de3f1 100644
--- a/src/GlyphCache.cpp
+++ b/src/GlyphCache.cpp
@@ -44,12 +44,18 @@ namespace
     // variable length structures.

     template<typename W>
-    class _glat_iterator : public std::iterator<std::input_iterator_tag, std::pair<sparse::key_type, sparse::mapped_type> >
+    class _glat_iterator
     {
         unsigned short  key() const             { return uint16(be::peek<W>(_e) + _n); }
         unsigned int    run() const             { return be::peek<W>(_e+sizeof(W)); }
         void            advance_entry()         { _n = 0; _e = _v; be::skip<W>(_v,2); }
     public:
+        using iterator_category = std::input_iterator_tag;
+        using value_type = std::pair<sparse::key_type, sparse::mapped_type>;
+        using difference_type = std::pair<sparse::key_type, sparse::mapped_type>;
+        using pointer = std::pair<sparse::key_type, sparse::mapped_type>*;
+        using reference = std::pair<sparse::key_type, sparse::mapped_type>&;
+        
         _glat_iterator(const void * glat=0) : _e(reinterpret_cast<const byte *>(glat)), _v(_e+2*sizeof(W)), _n(0) {}

         _glat_iterator<W> & operator ++ () {
diff --git a/src/Pass.cpp b/src/Pass.cpp
index db31c22d..c744bcbc 100644
--- a/src/Pass.cpp
+++ b/src/Pass.cpp
@@ -194,7 +194,7 @@ bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t su
         m_cPConstraint = vm::Machine::Code(true, pcCode, pcCode + pass_constraint_len,
                                   precontext[0], be::peek<uint16>(sort_keys), *m_silf, face, PASS_TYPE_UNKNOWN);
         if (e.test(!m_cPConstraint, E_OUTOFMEM)
-                || e.test(m_cPConstraint.status() != Code::loaded, m_cPConstraint.status() + E_CODEFAILURE))
+                || e.test(m_cPConstraint.status() != Code::loaded, m_cPConstraint.status() + static_cast<int> (E_CODEFAILURE)))
             return face.error(e);
         face.error_context(face.error_context() - 1);
     }
@@ -266,8 +266,8 @@ bool Pass::readRules(const byte * rule_map, const size_t num_entries,
         r->constraint = new (m_codes+n*2-1) vm::Machine::Code(true,  rc_begin, rc_end, r->preContext, r->sort, *m_silf, face, pt, &prog_pool_free);

         if (e.test(!r->action || !r->constraint, E_OUTOFMEM)
-                || e.test(r->action->status() != Code::loaded, r->action->status() + E_CODEFAILURE)
-                || e.test(r->constraint->status() != Code::loaded, r->constraint->status() + E_CODEFAILURE)
+                || e.test(r->action->status() != Code::loaded, r->action->status() + static_cast<int> (E_CODEFAILURE))
+                || e.test(r->constraint->status() != Code::loaded, r->constraint->status() + static_cast<int> (E_CODEFAILURE))
                 || e.test(!r->constraint->immutable(), E_MUTABLECCODE))
             return face.error(e);
     }