bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] stdbool: avoid rejecting clang


From: Bruno Haible
Subject: Re: [PATCH] stdbool: avoid rejecting clang
Date: Sun, 19 Dec 2010 15:32:12 +0100
User-agent: KMail/1.9.9

Paul Eggert wrote on 2010-08-24, in
<http://lists.gnu.org/archive/html/bug-gnulib/2010-08/msg00170.html>:
> the C standard
> says that "&s" is a valid static initializer, but I suppose
> one could argue that there's an implicit conversion to bool that would
> clearly be invalid if one made it explicit and wrote "(bool) &s" there.
> ...
> --- a/lib/autoconf/headers.m4
> +++ b/lib/autoconf/headers.m4
> @@ -628,7 +628,7 @@ AC_DEFUN([AC_HEADER_STDBOOL],
>       char b[false == 0 ? 1 : -1];
>       char c[__bool_true_false_are_defined == 1 ? 1 : -1];
>       char d[(bool) 0.5 == true ? 1 : -1];
> -     bool e = &s;
> +     /* See body of main program for 'e'.  */
>       char f[(_Bool) 0.0 == false ? 1 : -1];
>       char g[true];
>       char h[sizeof (_Bool)];
> @@ -666,6 +647,7 @@ AC_DEFUN([AC_HEADER_STDBOOL],
>       _Bool *pq = &q;
>        ]],
>        [[
> +     bool e = &s;
>       *pq |= q;
>       *pq |= ! q;
>       /* Refer to every declared value, to avoid compiler optimizations.  */

This issue occurs again with Compaq C V6.5-303 on OSF/1 5.1.

source='test-stdbool.c' object='test-stdbool.o' libtool=no  DEPDIR=.deps 
depmode=tru64 /bin/ksh ./../build-aux/depcomp  cc -O -DHAVE_CONFIG_H -I.  
-DGNULIB_STRICT_CHECKING=1  -I. -I.  -I.. -I./..  -I../gllib -I./../gllib  
-ieee   -c -o test-stdbool.o test-stdbool.c
cc: Error: test-stdbool.c, line 65: In the initializer for e, the address 
cannot be converted to the destination type. (badstaticcvt)
bool e = &s;
---------^
*** Exit 1

After the test in m4/stdbool.m4 has been relaxed, the unit test needs to be
relaxed accordingly. Here's the patch that I will push:


2010-12-19  Bruno Haible  <address@hidden>

        stdbool: Relax test.
        * tests/test-stdbool.c (e): Don't require that casts from a variable's
        address to 'bool' work in static initializer, for compilers other than
        GCC.

--- tests/test-stdbool.c.orig   Sun Dec 19 15:24:10 2010
+++ tests/test-stdbool.c        Sun Dec 19 15:23:08 2010
@@ -61,8 +61,13 @@
 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
 #if HAVE_STDBOOL_H || defined __GNUC__ /* See above.  */
 char d[(bool) 0.5 == true ? 1 : -1];
-# ifdef ADDRESS_CHECK_OKAY
+# 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__
 bool e = &s;
+#  endif
 # endif
 char f[(_Bool) 0.0 == false ? 1 : -1];
 #endif
@@ -85,6 +90,13 @@
 int
 main ()
 {
+#if HAVE_STDBOOL_H || defined __GNUC__ /* See above.  */
+# ifdef ADDRESS_CHECK_OKAY /* Avoid gcc warning.  */
+  /* A cast from a variable's address to bool is valid in expressions.  */
+  bool e1 = &s;
+# endif
+#endif
+
   /* 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



reply via email to

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