Jim Meyering <[EMAIL PROTECTED]> writes: > Besides, who knows... compilers may eventually be able to optimize > away that xalloc_die call, in spite of the intermediate size_t.
If GCC ever gets that smart, then it will issue the same warning as it does now without the unsigned_int hack. Shouldn't we simply fix GCC instead? Something like the following. (-Wextra is the new name for -W.) (Also I'd have to document this.) 2005-06-22 Paul Eggert <[EMAIL PROTECTED]> * c-common.c (shorten_compare): Unless -Wextra is used, do not warn against comparisons always being false due to limited range of data type. --- c-common.c 2005-06-22 12:42:13 -0700 +++ /tmp/c-common.c 2005-06-22 13:14:26 -0700 @@ -2112,7 +2112,8 @@ shorten_compare (tree *op0_ptr, tree *op type = c_common_unsigned_type (type); } - if (TREE_CODE (primop0) != INTEGER_CST) + if (extra_warnings && !in_system_header + && TREE_CODE (primop0) != INTEGER_CST) { if (val == truthvalue_false_node) warning (0, "comparison is always false due to limited range of data type"); It will take a while for this fix to propagate, though. In the meantime, why not modify the definition of xalloc_oversized(n,s) to always return 0 if if s is a constant and if the size of n is such that the comparison cannot possibly fail. Something like this? (completely untested): 2005-06-22 Paul Eggert <[EMAIL PROTECTED]> * xalloc.h: Work around a bogus GCC 4.0.0 warning "comparison is always false due to limited range of data type". Problem reported by Oskar Liljeblad. (xalloc_lt, xalloc_lt_always_false): New macros. (xalloc_oversized): Use them. --- xalloc.h 2005-05-14 01:02:58 -0700 +++ /tmp/xalloc.h 2005-06-22 13:53:19 -0700 @@ -56,6 +56,22 @@ void *x2nrealloc (void *p, size_t *pn, s void *xmemdup (void const *p, size_t s); char *xstrdup (char const *str); +/* Work around a bogus GCC 4.0.0 warning "comparison is always false + due to limited range of data type". */ + +# define xalloc_lt(m, n) (! xalloc_lt_always_false (m, n) && (m) < (n)) +# if __GNUC__ < 4 +# define xalloc_lt_always_false(a, b) 0 +# else +# ifndef CHAR_BIT +# include <limits.h> +# endif +# define xalloc_lt_always_false(m, n) \ + (__builtin_constant_p (m) \ + && sizeof (n) < sizeof (size_t) \ + && (size_t) 1 << (sizeof (n) * CHAR_BIT) <= (m)) \ +# endif + /* Return 1 if an array of N objects, each of size S, cannot exist due to size arithmetic overflow. S must be positive and N must be nonnegative. This is a macro, not an inline function, so that it @@ -69,7 +85,8 @@ char *xstrdup (char const *str); exactly-SIZE_MAX allocations on such hosts; this avoids a test and branch when S is known to be 1. */ # define xalloc_oversized(n, s) \ - ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) + xalloc_lt ((size_t) (sizeof(ptrdiff_t) <= sizeof(size_t) ? -1 : -2) / (s), \ + n) # ifdef __cplusplus } _______________________________________________ bug-gnulib mailing list bug-gnulib@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnulib