Muffle GCC warnings in various ways.
[u/mdw/catacomb] / math / mpint.h
index 7867f6a..f551980 100644 (file)
 
 /*----- Generic translation macros ----------------------------------------*/
 
+/* --- Warning damage control --- *
+ *
+ * GCC (at least) isn't clever enough to work out that the division in
+ * @MP_FROMINT@ is actually safe (since it will only be executed if @_i >
+ * MPW_MAX@, which would prove that @(type)MPW_MAX + 1 != 0@).  So here's
+ * some machinery to shut it up.
+ */
+
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  define MP_FROMINT_MUFFLE_WARNING(x) do {                            \
+       _Pragma("GCC diagnostic push")                                  \
+       _Pragma("GCC diagnostic ignored \"-Wdiv-by-zero\"")             \
+       x                                                               \
+       _Pragma("GCC diagnostic pop")                                   \
+   } while (0)
+#else
+#  define MP_FROMINT_MUFFLE_WARNING(x) do { x } while (0)
+#endif
+
 /* --- @MP_FROMINT@ --- *
  *
  * Arguments:  @d@ = destination multiprecision integer
@@ -71,7 +90,7 @@
       if (_i <= MPW_MAX)                                               \
        break;                                                          \
       else                                                             \
-       _i /= (type)MPW_MAX + 1;                                        \
+       MP_FROMINT_MUFFLE_WARNING({ _i /= (type)MPW_MAX + 1; });        \
     }                                                                  \
   } else {                                                             \
     _d->f |= MP_NEG;                                                   \
       if (_i >= -MPW_MAX)                                              \
        break;                                                          \
       else                                                             \
-       _i /= (type)MPW_MAX + 1;                                        \
+       MP_FROMINT_MUFFLE_WARNING({ _i /= (type)MPW_MAX + 1; });        \
     }                                                                  \
   }                                                                    \
                                                                        \