gbranden pushed a commit to branch master
in repository groff.

commit 12809b85e3e62097d59c57642b28c07a32b13b6d
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri May 16 06:39:33 2025 -0500

    [troff]: Trivially refactor.
    
    * src/roff/troff/dictionary.cpp (dictionary::lookup):
    * src/roff/troff/node.cpp (suppress_node::tprint): Favor function-style
      construction for temporaries over C-style type casts.
    
    * src/roff/troff/env.cpp (environment::make_tag):
    * src/roff/troff/input.cpp (set_string): Favor C++-style `static_cast`
      over C-style omnipotent casts.
    
    * src/roff/troff/mtsm.cpp (state_set::incl, state_set::excl)
      (state_set::is_in): Discard unnecessary C-style type casts of objects
      of enumerated type to `int`.  Pre-C++11 `enum`s like these are always
      backed by `int`s.
    
    Also stop cramming casts of return values up against the adjacent
    expression.
---
 ChangeLog                     | 14 ++++++++++++++
 src/roff/troff/dictionary.cpp |  4 ++--
 src/roff/troff/env.cpp        |  2 +-
 src/roff/troff/input.cpp      |  2 +-
 src/roff/troff/mtsm.cpp       | 24 ++++++++++++------------
 src/roff/troff/node.cpp       | 10 +++++-----
 src/roff/troff/number.cpp     |  4 +++-
 7 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dbf5a50c5..372e24d8d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-05-16  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/dictionary.cpp (dictionary::lookup):
+       * src/roff/troff/node.cpp (suppress_node::tprint): Favor
+       function-style construction for temporaries over C-style type
+       casts.
+       * src/roff/troff/env.cpp (environment::make_tag):
+       * src/roff/troff/input.cpp (set_string): Favor C++-style
+       `static_cast` over C-style omnipotent casts.
+       * src/roff/troff/mtsm.cpp (state_set::incl, state_set::excl)
+       (state_set::is_in): Discard unnecessary C-style type casts of
+       objects of enumerated type to `int`.  Pre-C++11 `enum`s like
+       these are always backed by `int`s.
+
 2025-05-16  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp: Trivially refactor.  Give the
diff --git a/src/roff/troff/dictionary.cpp b/src/roff/troff/dictionary.cpp
index ea1da1760..7b67cce73 100644
--- a/src/roff/troff/dictionary.cpp
+++ b/src/roff/troff/dictionary.cpp
@@ -66,7 +66,7 @@ void *dictionary::lookup(symbol s, void *v)
   ++used;
   table[i].v = v;
   table[i].s = s;
-  if ((double)used/(double)size >= threshold || used + 1 >= size) {
+  if ((double(used) / double(size) >= threshold) || used + 1 >= size) {
     int old_size = size;
     size = int(size * factor);
     while (!is_good_size(size))
@@ -76,7 +76,7 @@ void *dictionary::lookup(symbol s, void *v)
     used = 0;
     for (i = 0; i < old_size; i++)
       if (old_table[i].v != 0 /* nullptr */)
-       (void)lookup(old_table[i].s, old_table[i].v);
+       (void) lookup(old_table[i].s, old_table[i].v);
     delete[] old_table;
   }
   return 0 /* nullptr */;
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 3ebcc01c1..dc32cd062 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -2419,7 +2419,7 @@ node *environment::make_tag(const char *nm, int i)
     macro m;
     m.append_str("devtag:");
     for (const char *p = nm; *p; p++)
-      if (!is_invalid_input_char((unsigned char)*p))
+      if (!is_invalid_input_char(static_cast<unsigned char>(*p)))
        m.append(*p);
     m.append(' ');
     m.append_int(i);
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 969396636..e58b7f6c6 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -9132,7 +9132,7 @@ static void set_string(const char *name, const char 
*value)
 {
   macro *m = new macro;
   for (const char *p = value; *p != 0 /* nullptr */; p++)
-    if (!is_invalid_input_char((unsigned char)*p))
+    if (!is_invalid_input_char(static_cast<unsigned char>(*p)))
       m->append(*p);
   request_dictionary.define(name, m);
 }
diff --git a/src/roff/troff/mtsm.cpp b/src/roff/troff/mtsm.cpp
index 7c8252168..647909f6b 100644
--- a/src/roff/troff/mtsm.cpp
+++ b/src/roff/troff/mtsm.cpp
@@ -554,62 +554,62 @@ state_set::~state_set()
 
 void state_set::incl(bool_value_state b)
 {
-  boolset |= 1 << (int)b;
+  boolset |= 1 << b;
 }
 
 void state_set::incl(int_value_state i)
 {
-  intset |= 1 << (int)i;
+  intset |= 1 << i;
 }
 
 void state_set::incl(units_value_state u)
 {
-  unitsset |= 1 << (int)u;
+  unitsset |= 1 << u;
 }
 
 void state_set::incl(string_value_state s)
 {
-  stringset |= 1 << (int)s;
+  stringset |= 1 << s;
 }
 
 void state_set::excl(bool_value_state b)
 {
-  boolset &= ~(1 << (int)b);
+  boolset &= ~(1 << b);
 }
 
 void state_set::excl(int_value_state i)
 {
-  intset &= ~(1 << (int)i);
+  intset &= ~(1 << i);
 }
 
 void state_set::excl(units_value_state u)
 {
-  unitsset &= ~(1 << (int)u);
+  unitsset &= ~(1 << u);
 }
 
 void state_set::excl(string_value_state s)
 {
-  stringset &= ~(1 << (int)s);
+  stringset &= ~(1 << s);
 }
 
 int state_set::is_in(bool_value_state b)
 {
-  return (boolset & (1 << (int)b)) != 0;
+  return (boolset & (1 << b)) != 0;
 }
 
 int state_set::is_in(int_value_state i)
 {
-  return (intset & (1 << (int)i)) != 0;
+  return (intset & (1 << i)) != 0;
 }
 
 int state_set::is_in(units_value_state u)
 {
-  return (unitsset & (1 << (int)u)) != 0;
+  return (unitsset & (1 << u)) != 0;
 }
 
 int state_set::is_in(string_value_state s)
 {
-  return (stringset & (1 << (int)s)) != 0;
+  return (stringset & (1 << s)) != 0;
 }
 
 void state_set::add(units_value_state, int n)
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index aba7c4210..8be62a63c 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -4554,7 +4554,7 @@ void suppress_node::tprint(troff_output_file *out)
        if (len > (namebuflen - 1))
          error("constructed file name in suppressed output escape"
                " sequence is too long (>= %1 bytes); skipping image",
-               (int)namebuflen);
+               int(namebuflen));
        else
          strncpy(name, new_name, (namebuflen - 1));
        free(new_name);
@@ -4563,7 +4563,7 @@ void suppress_node::tprint(troff_output_file *out)
       else {
        if (image_filename_len > (namebuflen - 1))
          error("file name in suppressed output escape sequence is too"
-               " long (>= %1 bytes); skipping image", (int)namebuflen);
+               " long (>= %1 bytes); skipping image", int(namebuflen));
        else
          strcpy(name, image_filename);
       }
@@ -6512,10 +6512,10 @@ static bool mount_font_no_translate(int n, symbol name,
     if (check_only)
       return fm != 0 /* nullptr */;
     if (0 /* nullptr */ == fm) {
-      (void)font_dictionary.lookup(external_name, &a_char);
+      (void) font_dictionary.lookup(external_name, &a_char);
       return false;
     }
-    (void)font_dictionary.lookup(name, fm);
+    (void) font_dictionary.lookup(name, fm);
   }
   else if (p == &a_char) {
     return false;
@@ -6725,7 +6725,7 @@ font_family *lookup_family(symbol nm)
   font_family *f = (font_family *)family_dictionary.lookup(nm);
   if (!f) {
     f = new font_family(nm);
-    (void)family_dictionary.lookup(nm, f);
+    (void) family_dictionary.lookup(nm, f);
   }
   return f;
 }
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index c15129119..c12d491ad 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -650,7 +650,9 @@ units scale(units n, units x, units y)
       return (n * x) / y;
   }
   else {
-    if (-(unsigned)n <= -(unsigned)INT_MIN / x)
+    // I'd prefer to say "(unsigned int(n))", but C++ doesn't seem to
+    // permit function-style construction with a type qualifier.  --GBR
+    if (-(unsigned(n)) <= -(unsigned(INT_MIN)) / x)
       return (n * x) / y;
   }
   double res = n * double(x) / double(y);

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to