changeset 18368:679194d50123

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.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 17 Aug 2016 15:33:06 -0700
parents 43c61b332554
children 996d4e2cd2dd
files ChangeLog NEWS doc/posix-headers/stdbool.texi m4/stdbool.m4
diffstat 4 files changed, 32 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Aug 17 15:01:50 2016 -0700
+++ b/ChangeLog	Wed Aug 17 15:33:06 2016 -0700
@@ -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
--- a/NEWS	Wed Aug 17 15:01:50 2016 -0700
+++ b/NEWS	Wed Aug 17 15:33:06 2016 -0700
@@ -42,6 +42,10 @@
 
 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
--- a/doc/posix-headers/stdbool.texi	Wed Aug 17 15:01:50 2016 -0700
+++ b/doc/posix-headers/stdbool.texi	Wed Aug 17 15:33:06 2016 -0700
@@ -20,7 +20,8 @@
 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
--- a/m4/stdbool.m4	Wed Aug 17 15:01:50 2016 -0700
+++ b/m4/stdbool.m4	Wed Aug 17 15:33:06 2016 -0700
@@ -5,7 +5,7 @@
 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 @@
            [[
              #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 @@
               "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])])