]> Savannah Git Hosting - gnulib.git/commitdiff
intprops tests: Strengthen INT_PROMOTE tests.
authorBruno Haible <bruno@clisp.org>
Sun, 9 Feb 2025 05:07:13 +0000 (06:07 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 9 Feb 2025 05:07:13 +0000 (06:07 +0100)
* lib/intprops.h (INT_PROMOTE): Refine comment.
* tests/test-intprops.c: Check the size and sign of INT_PROMOTE (x) on
all compilers.
(main): Check that INT_PROMOTE is a no-op on floats.

ChangeLog
lib/intprops.h
tests/test-intprops.c

index 11912cd67aa0c2e02f6e2fe80ac84fc0cc0c630b..710db41aa860da3a00cab8ba5da796f4398fd193 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-02-09  Bruno Haible  <bruno@clisp.org>
+
+       intprops tests: Strengthen INT_PROMOTE tests.
+       * lib/intprops.h (INT_PROMOTE): Refine comment.
+       * tests/test-intprops.c: Check the size and sign of INT_PROMOTE (x) on
+       all compilers.
+       (main): Check that INT_PROMOTE is a no-op on floats.
+
 2025-02-08  Collin Funk  <collin.funk1@gmail.com>
 
        doc: Document free_aligned_sized and free_sized added in C23.
index 83efe39910aaf1025a37c362a391b0156f718455..2f9fa0a0222b68177d16ffee18c9c4a1809e25cd 100644 (file)
@@ -39,7 +39,7 @@
    then 'switch (INT_PROMOTE (E))' pacifies gcc -Wswitch-enum if some
    enum values are deliberately omitted from the switch's cases.
    Here, unary + is safer than a cast or inline function, as unary +
-   does only integer promotions.  */
+   does only integer promotions and is disallowed on pointers.  */
 #define INT_PROMOTE(e) (+ (e))
 
 
index 026c615abaf5bcdb128cffb2005453f03b53b6dc..6c06e47ab34d70278a84d5c6274af1f14433cd88 100644 (file)
          || defined __clang__))
 int check_INT_PROMOTE = _Generic (INT_PROMOTE ((short int) 0), int: 0);
 #endif
+/* For other compilers, check the size and sign of INT_PROMOTE (x).  */
+int check_INT_PROMOTE_size
+    [2 * (sizeof (INT_PROMOTE ((short int) 0)) == sizeof (int)) - 1];
+int check_INT_PROMOTE_sign
+    [2 * (INT_PROMOTE ((short int) -1) < 0) - 1];
 
 int int_minus_2 = -2;
 int int_1 = 1;
@@ -79,6 +84,9 @@ main (void)
   /* Use VERIFY for tests that must be integer constant expressions,
      ASSERT otherwise.  */
 
+  /* Check that INT_PROMOTE is a no-op on floats.  */
+  ASSERT (INT_PROMOTE (2.71828) > 2);
+
 #ifndef TEST_STDCKDINT
   /* TYPE_IS_INTEGER.  */
   ASSERT (TYPE_IS_INTEGER (bool));