[PATCH] stdc_rotate_left-tests: pacify -Woverflow

Paul Eggert <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
Problem found with gcc 16.1.1 20260515 (Red Hat 16.1.1-2) on i686.
* tests/test-stdc_rotate_left.c (test_stdc_rotate_left_ul):
* tests/test-stdc_rotate_right.c (test_stdc_rotate_right_ul): Use
preprocessor-time check, not a potentially runtime check, to see
whether to use 32- or 64-bit tests.  This pacifies gcc -Woverflow.
Include <limits.h> to get ULONG_MAX.
---
 ChangeLog                      | 10 ++++++++++
 tests/test-stdc_rotate_left.c  | 11 +++++++----
 tests/test-stdc_rotate_right.c | 11 +++++++----
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fe2bd22dd8..4d08951061 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2026-08-12  Paul Eggert  <[email protected]>
+
+	stdc_rotate_left-tests: pacify -Woverflow
+	Problem found with gcc 16.1.1 20260515 (Red Hat 16.1.1-2) on i686.
+	* tests/test-stdc_rotate_left.c (test_stdc_rotate_left_ul):
+	* tests/test-stdc_rotate_right.c (test_stdc_rotate_right_ul): Use
+	preprocessor-time check, not a potentially runtime check, to see
+	whether to use 32- or 64-bit tests.  This pacifies gcc -Woverflow.
+	Include <limits.h> to get ULONG_MAX.
+
 2026-08-12  Bruno Haible  <[email protected]>
 
 	omap-c++: Avoid clang UBSAN runtime errors.
diff --git a/tests/test-stdc_rotate_left.c b/tests/test-stdc_rotate_left.c
index 64cc5b8477..10723d4afc 100644
--- a/tests/test-stdc_rotate_left.c
+++ b/tests/test-stdc_rotate_left.c
@@ -21,6 +21,8 @@
 /* Specification.  */
 #include <stdbit.h>
 
+#include <limits.h>
+
 #include "macros.h"
 
 #define TEST_CASE(type, function, value, shift, expect)         \
@@ -437,10 +439,11 @@ test_stdc_rotate_left_ui (void)
 static void
 test_stdc_rotate_left_ul (void)
 {
-  if (sizeof 0ul < sizeof 0ull)
-    TEST_CASES_32 (unsigned long int, stdc_rotate_left_ul);
-  else
-    TEST_CASES_64 (unsigned long int, stdc_rotate_left_ul);
+#if ULONG_MAX >> 31 == 1
+  TEST_CASES_32 (unsigned long int, stdc_rotate_left_ul);
+#else
+  TEST_CASES_64 (unsigned long int, stdc_rotate_left_ul);
+#endif
 }
 
 static void
diff --git a/tests/test-stdc_rotate_right.c b/tests/test-stdc_rotate_right.c
index 715a447c19..0ffdd928d5 100644
--- a/tests/test-stdc_rotate_right.c
+++ b/tests/test-stdc_rotate_right.c
@@ -21,6 +21,8 @@
 /* Specification.  */
 #include <stdbit.h>
 
+#include <limits.h>
+
 #include "macros.h"
 
 #define TEST_CASE(type, function, value, shift, expect)         \
@@ -437,10 +439,11 @@ test_stdc_rotate_right_ui (void)
 static void
 test_stdc_rotate_right_ul (void)
 {
-  if (sizeof 0ul < sizeof 0ull)
-    TEST_CASES_32 (unsigned long int, stdc_rotate_right_ul);
-  else
-    TEST_CASES_64 (unsigned long int, stdc_rotate_right_ul);
+#if ULONG_MAX >> 31 == 1
+  TEST_CASES_32 (unsigned long int, stdc_rotate_right_ul);
+#else
+  TEST_CASES_64 (unsigned long int, stdc_rotate_right_ul);
+#endif
 }
 
 static void
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.