]> Savannah Git Hosting - gnulib.git/commitdiff
stdbool tests: Enable the stricter tests also on clang.
authorBruno Haible <bruno@clisp.org>
Sun, 9 Aug 2020 16:55:26 +0000 (18:55 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 Aug 2020 16:55:26 +0000 (18:55 +0200)
* tests/test-stdbool.c (ADDRESS_CHECK_OKAY): Define also on clang.
(e): Enable the address-to-bool conversion test also on clang.

ChangeLog
tests/test-stdbool.c

index 7b23978c39b62d74328fb397a82a70dca4581d4d..b1fd086405830e981b3836be48ae04a915365884 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-08-09  Bruno Haible  <bruno@clisp.org>
+
+       stdbool tests: Enable the stricter tests also on clang.
+       * tests/test-stdbool.c (ADDRESS_CHECK_OKAY): Define also on clang.
+       (e): Enable the address-to-bool conversion test also on clang.
+
 2020-08-09  Bruno Haible  <bruno@clisp.org>
 
        count-one-bits: Use __builtin_popcount{,l,ll} on clang.
index b128b55d717c20314907990d8b62b934e9e9b388..4a8214650692d7252271454f262b45534b7e39a5 100644 (file)
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
 
-/* We want this test to succeed even when using gcc's -Werror; but to
-   do that requires a pragma that didn't exist before 4.3.0.  */
-#ifndef __GNUC__
+/* Define ADDRESS_CHECK_OKAY if it is OK to assign an address to a 'bool'
+   and this does not generate a warning (because we want this test to succeed
+   even when using gcc's -Werror).  */
+#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) \
+    || (__clang_major__ >= 4)
+/* We can silence the warning.  */
+# pragma GCC diagnostic ignored "-Waddress"
 # define ADDRESS_CHECK_OKAY
-#elif __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
-/* No way to silence -Waddress.  */
+#elif defined __GNUC__ || defined __clang__
+/* There may be a warning.  */
 #else
-# pragma GCC diagnostic ignored "-Waddress"
+/* Ignore warnings from other compilers.  */
 # define ADDRESS_CHECK_OKAY
 #endif
 
 
 /* Several tests cannot be guaranteed with gnulib's <stdbool.h>, at
    least, not for all compilers and compiler options.  */
-#if HAVE_STDBOOL_H || 3 <= __GNUC__
+#if HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__
 struct s { _Bool s: 1; _Bool t; } s;
 #endif
 
 char a[true == 1 ? 1 : -1];
 char b[false == 0 ? 1 : -1];
 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
-#if HAVE_STDBOOL_H || 3 <= __GNUC__ /* See above.  */
+#if HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__ /* See above.  */
 char d[(bool) 0.5 == true ? 1 : -1];
 # ifdef ADDRESS_CHECK_OKAY /* Avoid gcc warning.  */
 /* C99 may plausibly be interpreted as not requiring support for a cast from
    a variable's address to bool in a static initializer.  So treat it like a
    GCC extension.  */
-#  ifdef __GNUC__
+#  if defined __GNUC__ || defined __clang__
 bool e = &s;
 #  endif
 # endif
@@ -73,7 +77,7 @@ char f[(_Bool) 0.0 == false ? 1 : -1];
 #endif
 char g[true];
 char h[sizeof (_Bool)];
-#if HAVE_STDBOOL_H || 3 <= __GNUC__ /* See above.  */
+#if HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__ /* See above.  */
 char i[sizeof s.t];
 #endif
 enum { j = false, k = true, l = false * true, m = true * 256 };
@@ -92,7 +96,7 @@ main ()
 {
   int error = 0;
 
-#if HAVE_STDBOOL_H || 3 <= __GNUC__ /* See above.  */
+#if HAVE_STDBOOL_H || 3 <= __GNUC_ || 4 <= __clang_major___ /* See above.  */
 # ifdef ADDRESS_CHECK_OKAY /* Avoid gcc warning.  */
   /* A cast from a variable's address to bool is valid in expressions.  */
   {