issue with Microsoft compiler

Marc Glisse marc.glisse at inria.fr
Mon Feb 13 11:54:50 CET 2023


On Mon, 13 Feb 2023, Niels Möller wrote:

> I got the impression that someone was building GMP with -Werror.

Then I agree that it is their problem.

> Getting this by just *using* gmp and including gmp.h is
> a different setting with different tradeoffs.
>
> It might make some sense to add something like
>
>  #ifdef _MSC_VER
>  # pragma warning(disable:4146)
>  #endif
>
> to the installed gmp.h, if that is deemed not too brittle (I don't know
> how stable warning numbers are, or if there's some better way). I got
> _MCS_VER from a quick look at
> https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170
[...]
> Is the pragma a documented / recommended way to disable the warning?

The numbers seem stable, and the pragma is advertised by Microsoft 
(https://learn.microsoft.com/en-us/cpp/preprocessor/warning?view=msvc-170) 
and used by many projects 
(https://github.com/CGAL/cgal/blob/master/Number_types/include/CGAL/gmp.h). 
You are supposed to use push/pop as well, though, in a header.

#ifdef _MSC_VER
#  pragma warning(push)
#  pragma warning(disable:4146)
#endif

... code ...

#ifdef _MSC_VER
#  pragma warning(pop)
#endif


Another option, if it is just the one place in gmp.h, would be to replace 
-X with 0-X (or the uglier ~X+1 but that does not seem necessary).

-- 
Marc Glisse


More information about the gmp-bugs mailing list