]> Savannah Git Hosting - gnulib.git/commitdiff
intprops.h: use __typeof__ with GCC 7
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 29 Aug 2016 17:08:32 +0000 (10:08 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 29 Aug 2016 17:09:50 +0000 (10:09 -0700)
* lib/intprops.h (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW)
(_GL_MULTIPLY_OVERFLOW): Use __typeof__ as in the GCC manual.
This avoids computing the expression's value (which might overflow!).

ChangeLog
lib/intprops.h

index 8e7ab7475703b9e4b18f786afc04390ec8098548..70012b70bba57728213fa46e03231045f15e9be6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-08-29  Paul Eggert  <eggert@cs.ucla.edu>
+
+       intprops.h: use __typeof__ with GCC 7
+       * lib/intprops.h (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW)
+       (_GL_MULTIPLY_OVERFLOW): Use __typeof__ as in the GCC manual.
+       This avoids computing the expression's value (which might overflow!).
+
 2016-08-29  Jim Meyering  <meyering@fb.com>
 
        intprops.h, xalloc-oversized.h: work with gcc 7
index d2a65cc5e4571f02237a614171ffa2a4e1741d46..32ee71a0fd60ac908a3bb99a720f7571befcffcb 100644 (file)
@@ -240,11 +240,11 @@ verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
    that the result (e.g., A + B) has that type.  */
 #if _GL_HAS_BUILTIN_OVERFLOW_P
 # define _GL_ADD_OVERFLOW(a, b, min, max)                               \
-   __builtin_add_overflow_p (a, b, (a) + (b))
+   __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
 # define _GL_SUBTRACT_OVERFLOW(a, b, min, max)                          \
-   __builtin_sub_overflow_p (a, b, (a) - (b))
+   __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0)
 # define _GL_MULTIPLY_OVERFLOW(a, b, min, max)                          \
-   __builtin_mul_overflow_p (a, b, (a) * (b))
+   __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0)
 #elif _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL
 # define _GL_ADD_OVERFLOW(a, b, min, max)                               \
    __builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0)