From: Paul Eggert Date: Sat, 15 Nov 2025 08:55:47 +0000 (-0800) Subject: Port intmax macro to strict C11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0521528cdfbce4f00a2aa3b8623c916b257c9783;p=thirdparty%2Ftar.git Port intmax macro to strict C11 Needed for Apple clang version 14.0.0 (clang-1400.0.29.202). * src/common.h (intmax): Define macro only if _Generic works, and use _Generic in it rather that using EXPR_SIGNED. This is needed to make the first argument of verify_expr an integer constant expression, which is required for strict C11. Although GCC is smart enough to treat (1 ? 0 : V) as an integer constant expression even if V is an integer variable, C11 does not require support for this sort of thing. --- diff --git a/src/common.h b/src/common.h index 101c5db8..28be0228 100644 --- a/src/common.h +++ b/src/common.h @@ -683,7 +683,15 @@ intmax (intmax_t n) } /* intmax should be used only with signed types. To bypass this check parenthesize the function, e.g., (intmax) (n). */ -#define intmax(n) verify_expr (EXPR_SIGNED (n), (intmax) (n)) +#if 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS +# define intmax(n) \ + verify_expr (_Generic (n, \ + unsigned char: 0, unsigned short int: 0, \ + unsigned int: 0, unsigned long int: 0, \ + unsigned long long int: 0, \ + default: 1), \ + (intmax) (n)) +#endif /* Represent N using a signed integer I such that (uintmax_t) I == N. With a good optimizing compiler, this is equivalent to (intmax_t) i