]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Port intmax macro to strict C11
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Nov 2025 08:55:47 +0000 (00:55 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Nov 2025 23:10:48 +0000 (15:10 -0800)
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.

src/common.h

index 101c5db8e7ca19cd99e1585872f7a9f5b2ed18c0..28be02283d5ee5d94594ec0f8a641a366aee3a4f 100644 (file)
@@ -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