bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] stdbool: avoid rejecting clang


From: Eric Blake
Subject: [PATCH] stdbool: avoid rejecting clang
Date: Mon, 23 Aug 2010 17:17:38 -0600

* m4/stdbool.m4 (AC_HEADER_STDBOOL): Resync with autoconf.
* tests/test-stdbool.c: Enable more tests if using the system
<stdbool.h> instead of the gnulib replacement.
(main): Move xlc bug test to a runtime test for all compilers.
Reported by Anders Kaseorg.

Signed-off-by: Eric Blake <address@hidden>
---

Here's the gnulib counterpart that adds the promised testing to
test-stdbool.c.  I've tested it with gcc 3.4.4, 4.3.4, 4.4.4, clang,
and Solaris /usr/bin/cc.  All the gcc tests were done with and without
-Werror.  There may be additional fallout with other compilers, but
more testing is always desirable, so I'm about to commit this.

Meanwhile, if we can determine that (char*)0 is better than digs,
while still exposing the AIX bug, then Anders' patch proposal may
still be worth folding into m4/stdbool.m4.

 ChangeLog            |    7 ++++++
 m4/stdbool.m4        |   15 +++++++------
 tests/test-stdbool.c |   51 ++++++++++++++++++++++++-------------------------
 3 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 37f8da3..6429e2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-08-23  Eric Blake  <address@hidden>

+       stdbool: avoid rejecting clang
+       * m4/stdbool.m4 (AC_HEADER_STDBOOL): Resync with autoconf.
+       * tests/test-stdbool.c: Enable more tests if using the system
+       <stdbool.h> instead of the gnulib replacement.
+       (main): Move xlc bug test to a runtime test for all compilers.
+       Reported by Anders Kaseorg.
+
        argz: fix shell quoting issue
        * m4/argz.m4 (gl_FUNC_ARGZ): Allow for spaces in argument.
        Reported by Charles Wilson.
diff --git a/m4/stdbool.m4 b/m4/stdbool.m4
index 3d672d7..fed31d9 100644
--- a/m4/stdbool.m4
+++ b/m4/stdbool.m4
@@ -5,6 +5,8 @@ dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.

+#serial 2
+
 # Prepare for substituting <stdbool.h> if it is not supported.

 AC_DEFUN([AM_STDBOOL_H],
@@ -31,8 +33,9 @@ AC_DEFUN([AM_STDBOOL_H],
 # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
 AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])

-# This macro is only needed in autoconf <= 2.59.  Newer versions of autoconf
-# have this macro built-in.
+# This version of the macro is needed in autoconf <= 2.67.  Autoconf has
+# it built in since 2.60, but we want the tweaks from the 2.68 version
+# to avoid rejecting clang due to relying on extensions.

 AC_DEFUN([AC_HEADER_STDBOOL],
   [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
@@ -74,7 +77,7 @@ AC_DEFUN([AC_HEADER_STDBOOL],
           _Bool n[m];
           char o[sizeof n == m * sizeof n[0] ? 1 : -1];
           char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
-          #if defined __xlc__ || defined __GNUC__
+          #ifdef __xlc__
            /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
               reported by James Lemley on 2005-10-05; see
               
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
@@ -87,11 +90,9 @@ AC_DEFUN([AC_HEADER_STDBOOL],
               support for this kind of constant expression.  In the
               meantime, this test will reject xlc, which is OK, since
               our stdbool.h substitute should suffice.  We also test
-              this with GCC, where it should work, to detect more
-              quickly whether someone messes up the test in the
-              future.  */
+              in test-stdbool.c to ensure nothing else messes up.  */
            char digs[] = "0123456789";
-           int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
+           int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : 0);
           #endif
           /* Catch a bug in an HP-UX C compiler.  See
              http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
diff --git a/tests/test-stdbool.c b/tests/test-stdbool.c
index fcb534d..b0db806 100644
--- a/tests/test-stdbool.c
+++ b/tests/test-stdbool.c
@@ -16,6 +16,17 @@

 /* Written by Bruno Haible <address@hidden>, 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
+#elif __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
+/* No way to silence -Waddress.  */
+#else
+# pragma GCC diagnostic ignored "-Waddress"
+# define ADDRESS_CHECK_OKAY
+#endif
+
 #include <config.h>

 #include <stdbool.h>
@@ -39,49 +50,31 @@
  "error: __bool_true_false_are_defined is not defined"
 #endif

-#if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>.  */
+/* Several tests cannot be guaranteed with gnulib's <stdbool.h>, at
+   least, not for all compilers and compiler options.  */
+#if HAVE_STDBOOL_H || defined __GNUC__
 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 0 /* Cannot be guaranteed with gnulib's <stdbool.h>, at least,
-not for all compilers.  */
+#if HAVE_STDBOOL_H || defined __GNUC__ /* See above.  */
 char d[(bool) 0.5 == true ? 1 : -1];
+# ifdef ADDRESS_CHECK_OKAY
 bool e = &s;
+# endif
 char f[(_Bool) 0.0 == false ? 1 : -1];
 #endif
 char g[true];
 char h[sizeof (_Bool)];
-#if 0 /* See above.  */
+#if HAVE_STDBOOL_H || defined __GNUC__ /* See above.  */
 char i[sizeof s.t];
 #endif
 enum { j = false, k = true, l = false * true, m = true * 256 };
 _Bool n[m];
 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
-#if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>.  */
-#if defined __xlc__ || defined __GNUC__
- /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
-    reported by James Lemley on 2005-10-05; see
-    http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
-    This test is not quite right, since xlc is allowed to
-    reject this program, as the initializer for xlcbug is
-    not one of the forms that C requires support for.
-    However, doing the test right would require a run-time
-    test, and that would make cross-compilation harder.
-    Let us hope that IBM fixes the xlc bug, and also adds
-    support for this kind of constant expression.  In the
-    meantime, this test will reject xlc, which is OK, since
-    our stdbool.h substitute should suffice.  We also test
-    this with GCC, where it should work, to detect more
-    quickly whether someone messes up the test in the
-    future.  */
- char digs[] = "0123456789";
- int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
-#endif
-#endif
 /* Catch a bug in an HP-UX C compiler.  See
    http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
    http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
@@ -92,5 +85,11 @@ _Bool *pq = &q;
 int
 main ()
 {
-  return 0;
+  /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
+     reported by James Lemley on 2005-10-05; see
+     http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
+     This is a runtime test, since a corresponding compile-time
+     test would rely on initializer extensions.  */
+  char digs[] = "0123456789";
+  return &(digs + 5)[-2 + (bool) 1] == &digs[4] ? 0 : 1;
 }
-- 
1.7.2.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]