X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/35c0995dde0c37486681630acdd8d26659a4732e..aa02ed367404c659ab7205ef9662ef92032d7786:/math/mpint.h diff --git a/math/mpint.h b/math/mpint.h index 7867f6a..f551980 100644 --- a/math/mpint.h +++ b/math/mpint.h @@ -42,6 +42,25 @@ /*----- 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; \ @@ -84,7 +103,7 @@ if (_i >= -MPW_MAX) \ break; \ else \ - _i /= (type)MPW_MAX + 1; \ + MP_FROMINT_MUFFLE_WARNING({ _i /= (type)MPW_MAX + 1; }); \ } \ } \ \