]> Savannah Git Hosting - gnulib.git/commitdiff
stdbool: don't require _Bool for C++
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 Aug 2016 22:33:06 +0000 (15:33 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 Aug 2016 22:35:35 +0000 (15:35 -0700)
Problem reported by David Seifert in:
http://lists.gnu.org/archive/html/bug-gnulib/2016-06/msg00005.html
* NEWS, doc/posix-headers/stdbool.texi (stdbool.h): Document this.
* m4/stdbool.m4 (AC_CHECK_HEADER_STDBOOL): Make the check
more-forgiving for C++, in that it requires only 'bool'.  Be a bit
stricter about checking that bool and _Bool are compatible in C.

ChangeLog
NEWS
doc/posix-headers/stdbool.texi
m4/stdbool.m4

index e899eb4b7455ef621a08926a2e1630d24ba14dd5..ddacf1ed18430ed4c3d6e41c6ec184da6de4e3b4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-08-17  Paul Eggert  <eggert@cs.ucla.edu>
+
+       stdbool: don't require _Bool for C++
+       Problem reported by David Seifert in:
+       http://lists.gnu.org/archive/html/bug-gnulib/2016-06/msg00005.html
+       * NEWS, doc/posix-headers/stdbool.texi (stdbool.h): Document this.
+       * m4/stdbool.m4 (AC_CHECK_HEADER_STDBOOL): Make the check
+       more-forgiving for C++, in that it requires only 'bool'.  Be a bit
+       stricter about checking that bool and _Bool are compatible in C.
+
 2016-08-16  Paul Eggert  <eggert@cs.ucla.edu>
 
        getdelim: remove dependency on realloc-posix
diff --git a/NEWS b/NEWS
index 00709e8708ce8c0b41da5710f2123b2453ed44e7..e33d350146b9ab3a5e9155421c33b91f25506dad 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,10 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2016-08-17  stdbool         This no longer supports _Bool for C++.
+                            Programs intended to be portable to C++
+                            compilers should use plain 'bool' instead.
+
 2016-04-12  intprops        The following macros were removed:
                             TYPE_TWOS_COMPLEMENT  TYPE_ONES_COMPLEMENT
                             TYPE_SIGNED_MAGNITUDE
index 50afbd41f8aebc23ea3ecb514cfe5c56e728d86b..bac30aaf7b71937807d0dca3496011dcfee2c08a 100644 (file)
@@ -20,7 +20,8 @@ OpenBSD 4.7 with gcc 2.95.
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-@code{<stdbool.h>} must be #included before @samp{_Bool} can be used.
+@samp{_Bool} cannot be used before @code{<stdbool.h>} is included, or if
+the program is intended to be compiled by a C++ compiler.
 @item
 You cannot assume that @code{_Bool} is a typedef; it might be a macro.
 @item
index a556153181760a24d9810a798637e7424fcf12e7..2a9b1db86f3a338ee6bdcbc769deca523de4f73a 100644 (file)
@@ -5,7 +5,7 @@ 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 6
+#serial 7
 
 # Prepare for substituting <stdbool.h> if it is not supported.
 
@@ -44,7 +44,10 @@ AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
            [[
              #include <stdbool.h>
 
-             #if __cplusplus < 201103
+             #ifdef __cplusplus
+              typedef bool Bool;
+             #else
+              typedef _Bool Bool;
               #ifndef bool
                "error: bool is not defined"
               #endif
@@ -66,37 +69,38 @@ AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
               "error: __bool_true_false_are_defined is not defined"
              #endif
 
-             struct s { _Bool s: 1; _Bool t; } s;
+             struct s { Bool s: 1; Bool t; bool u: 1; bool v; } s;
 
              char a[true == 1 ? 1 : -1];
              char b[false == 0 ? 1 : -1];
              char c[__bool_true_false_are_defined == 1 ? 1 : -1];
              char d[(bool) 0.5 == true ? 1 : -1];
              /* See body of main program for 'e'.  */
-             char f[(_Bool) 0.0 == false ? 1 : -1];
+             char f[(Bool) 0.0 == false ? 1 : -1];
              char g[true];
-             char h[sizeof (_Bool)];
+             char h[sizeof (Bool)];
              char i[sizeof s.t];
              enum { j = false, k = true, l = false * true, m = true * 256 };
              /* The following fails for
                 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
-             _Bool n[m];
+             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];
+             char p[-1 - (Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
              /* 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
               */
-             _Bool q = true;
-             _Bool *pq = &q;
+             Bool q = true;
+             Bool *pq = &q;
+             bool *qq = &q;
            ]],
            [[
              bool e = &s;
-             *pq |= q;
-             *pq |= ! q;
+             *pq |= q; *pq |= ! q;
+             *qq |= q; *qq |= ! q;
              /* Refer to every declared value, to avoid compiler optimizations.  */
              return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
-                     + !m + !n + !o + !p + !q + !pq);
+                     + !m + !n + !o + !p + !q + !pq + !qq);
            ]])],
         [ac_cv_header_stdbool_h=yes],
         [ac_cv_header_stdbool_h=no])])