INT_MAX definition in gmp-impl.h conflicts with limits.h

Marc Glisse marc.glisse at inria.fr
Wed Nov 23 14:38:56 CET 2011


On Wed, 23 Nov 2011, Torbjorn Granlund wrote:

> Marc Glisse <marc.glisse at inria.fr> writes:
>
>  I was compiling gmp with clang (no issue except for the use of jb,pt
>  in mpn/x86_64/mod_34lsub1.asm), and then I ran the testsuite and hit
>  this issue: on linux, limits.h includes bits/xopen_lim.h which
>  contains this code:
>
>  #ifdef INT_MAX
>  # if INT_MAX == 32767
>  #  define WORD_BIT      16
>  ...
>
>  On the other hand, gmp-impl.h defines INT_MAX as something not
>  preprocessor-friendly (with casts). The combination doesn't work. I
>  can work around it by including tests.h before gmp-impl.h in the C++
>  test files, but that doesn't feel right.
>
>  Any opinion on the best way to go about this?
>
> Why is only one compiler affected?  Does GMP somehow #include different
> files for different compilers?

Here is the chain of includes:
In file included from /data/repos/gmp/tests/cxx/t-mix.cc:25:
In file included from /data/repos/gmp/tests/tests.h:477:
In file included from /tmp/libc++/inst/include/c++/v1/sstream:174:
In file included from /tmp/libc++/inst/include/c++/v1/ostream:130:
In file included from /tmp/libc++/inst/include/c++/v1/ios:216:
In file included from /tmp/libc++/inst/include/c++/v1/__locale:18:
In file included from /tmp/libc++/inst/include/c++/v1/mutex:176:
In file included from /tmp/libc++/inst/include/c++/v1/__mutex_base:15:
In file included from /tmp/libc++/inst/include/c++/v1/chrono:255:
In file included from /tmp/libc++/inst/include/c++/v1/ratio:70:
In file included from /tmp/libc++/inst/include/c++/v1/climits:42:
In file included from /tmp/clang/inst/bin/../lib/clang/3.1/include/limits.h:38:
In file included from /usr/include/limits.h:153:
/usr/include/x86_64-linux-gnu/bits/xopen_lim.h

With other standard libraries, sstream apparently manages without 
including limits.h (for instance, in libstdc++, ratio uses the builtin 
version of the constants normally defined in limits.h).

For now we could work around the problem by including tests.h before 
gmp-impl.h, and postpone thinking about this until that breaks too. But I 
wanted to check if you had a better idea.

-- 
Marc Glisse


More information about the gmp-bugs mailing list