On Do, 2016-06-02 at 15:01 -0700, Paul Eggert wrote:
> On 06/02/2016 02:26 PM, David Seifert wrote:
> > 
> > We could relax the whole thing a bit, and maybe just make a plain
> > __cplusplus check, without a version number. This keeps the C side
> > as
> > it always has been, but allows C++'s proper literals to kick in.
> > 
> > In addition, _Bool is also a major obstacle, as it does not exist
> > in
> > C++ (and does so only for GCC due to some GNUisms in libstdc++ with
> > -std=c++98). Would you consider moving away from _Bool and
> > replacing
> > all uses of it with bool? After all, <stdbool.h> by itself only
> > mandates the existence of bool/true/false.
> Sure, that all sounds fine (in C++ only of course).

Dear Paul,
attached the patch. I believe this patch in fact increases strictness
even for C code, as it relies on the proper functioning of the "bool"
macro. I have tested it with multiple C and C++ compilers on OS X and
Linux:

OS X (current stdbool.m4):
CC = gcc-apple-4.2
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = gcc-mp-5
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = gcc-mp-6
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = clang-mp-3.7
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = g++-apple-4.2
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = g++-mp-5
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = g++-mp-6
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = clang++-mp-3.7
checking for stdbool.h that conforms to C99... no
checking for _Bool... no


OS X (new stdbool.m4):
C = gcc-apple-4.2
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = gcc-mp-5
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = gcc-mp-6
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = clang-mp-3.7
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = g++-apple-4.2
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = g++-mp-5
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = g++-mp-6
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = clang++-mp-3.7
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no


Linux (current stdbool.m4):
CC = gcc-4.9.3
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = gcc-5.3.0
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = clang-3.8
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = g++-4.9.3
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = g++-5.3.0
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = clang++-3.8
checking for stdbool.h that conforms to C99... no
checking for _Bool... no


Linux (new stdbool.m4):
CC = gcc-4.9.3
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = gcc-5.3.0
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = clang-3.8
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes

CC = g++-4.9.3
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = g++-5.3.0
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

CC = clang++-3.8
checking for stdbool.h that conforms to C99... yes
checking for _Bool... no

As you can see, it works for Clang++ now too.

Regards
David
From d89f715f1a9e967a0ba246a5c226b51a76035f5c Mon Sep 17 00:00:00 2001
From: David Seifert <s...@gentoo.org>
Date: Fri, 3 Jun 2016 21:35:20 +0200
Subject: [PATCH] Make stdbool.m4 as compatible as possible for C++

---
 m4/stdbool.m4 | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/m4/stdbool.m4 b/m4/stdbool.m4
index a556153..463092e 100644
--- a/m4/stdbool.m4
+++ b/m4/stdbool.m4
@@ -44,7 +44,7 @@ AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
            [[
              #include <stdbool.h>
 
-             #if __cplusplus < 201103
+             #ifndef __cplusplus
               #ifndef bool
                "error: bool is not defined"
               #endif
@@ -66,29 +66,29 @@ 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; } 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 e = &s;
-- 
2.8.3

Reply via email to