Work around gcc issues with limits.h not defining LLONG_MIN

It looks like there are several cases where this might happen:

- In some MinGW distributions, the LLONG_MIN/etc defines are guarded
with:

	#if !defined(__STRICT_ANSI__) && defined(__GNUC__)

Which means that you don't get them in strict ANSI mode. The previous
workaround was specifically targeted towards this.

- In some GCC distributions (notably GCC 6.3.0 in some configurations),
LLONG_MIN/etc. defines are guarded with:

	#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)

But __STDC_VERSION__ isn't defined as C99 even if you use -std=c++14 -
which is probably technically valid, but not useful.

To work around this, redefine the symbols whenever we are building with
GCC and we need them and they aren't defined - doing this is better than
not building. Instead of hard-coding the constants, use GCC-specific
__LONG_LONG_MAX__ to compute them.

Fixes #181.
This commit is contained in:
Arseny Kapoulkine 2018-02-22 08:11:02 -08:00
parent 9bb468b3a9
commit 2ec3579f29

View file

@ -120,11 +120,11 @@ using std::memmove;
using std::memset;
#endif
// Some MinGW versions have headers that erroneously omit LLONG_MIN/LLONG_MAX/ULLONG_MAX definitions in strict ANSI mode
#if defined(PUGIXML_HAS_LONG_LONG) && defined(__MINGW32__) && defined(__STRICT_ANSI__) && !defined(LLONG_MAX) && !defined(LLONG_MIN) && !defined(ULLONG_MAX)
# define LLONG_MAX 9223372036854775807LL
# define LLONG_MIN (-LLONG_MAX-1)
# define ULLONG_MAX (2ULL*LLONG_MAX+1)
// Some MinGW/GCC versions have headers that erroneously omit LLONG_MIN/LLONG_MAX/ULLONG_MAX definitions from limits.h in some configurations
#if defined(PUGIXML_HAS_LONG_LONG) && defined(__GNUC__) && !defined(LLONG_MAX) && !defined(LLONG_MIN) && !defined(ULLONG_MAX)
# define LLONG_MIN (-LLONG_MAX - 1LL)
# define LLONG_MAX __LONG_LONG_MAX__
# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
#endif
// In some environments MSVC is a compiler but the CRT lacks certain MSVC-specific features