Two changes from September 2022 broke the GNU clisp build in the
"debug-gcsafety"
mode. Namely, in this mode, we use CC="g++" at configure time (since most of
clisp
is built with a C++ compiler) and CC="g++ -x c" only for the sources imported
from
Gnulib. As a consequence, HAVE_C_STATIC_ASSERT and HAVE_C_BOOL are both 1, but
this reflects only the language support in C++ mode. When compiling C source
files,
one needs to consider the language support in C mode.
The fix below makes this work with GCC and clang; other compilers are not
relevant
for this mode of building GNU clisp.
The empirically determined replacement for HAVE_C_STATIC_ASSERT is:
static_assert is built-in
- C++
g++ if __cplusplus >= 201103L && __GNUG__ >= 6
clang++ if __cplusplus >= 201703L
- C
gcc: if __STDC_VERSION__ >= 202000L && __GNUC__ >= 13
clang: if __STDC_VERSION__ >= 202000L && __clang_major__ >= 16
The empirically determined replacement for HAVE_C_BOOL is:
bool is built-in
- C++ always
- C
gcc: if __STDC_VERSION__ >= 202000L && __GNUC__ >= 13
clang: if __STDC_VERSION__ >= 202000L && __clang_major__ >= 15
2024-10-29 Bruno Haible <[email protected]>
assert-h, stdbool: Allow mixed use of gcc/g++ and clang/clang++ again.
* m4/assert_h.m4 (gl_ASSERT_H): Improve indentation. With GCC and clang,
don't use the value of HAVE_C_STATIC_ASSERT.
* m4/c-bool.m4 (gl_C_BOOL): With GCC and clang, don't use the value of
HAVE_C_BOOL.
diff --git a/m4/assert_h.m4 b/m4/assert_h.m4
index e1ee068f07..9bdb3c4f03 100644
--- a/m4/assert_h.m4
+++ b/m4/assert_h.m4
@@ -1,5 +1,5 @@
# assert_h.m4
-# serial 1
+# serial 2
dnl Copyright (C) 2011-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -13,30 +13,31 @@ AC_DEFUN([gl_ASSERT_H]
AC_CACHE_CHECK([for static_assert], [gl_cv_static_assert],
[gl_saved_CFLAGS=$CFLAGS
for gl_working in "yes, a keyword" "yes, an <assert.h> macro"; do
- AS_CASE([$gl_working],
- [*assert.h*], [CFLAGS="$gl_saved_CFLAGS -DINCLUDE_ASSERT_H"])
-
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[#if defined __clang__ && __STDC_VERSION__ < 202311
- #pragma clang diagnostic error "-Wc2x-extensions"
- #pragma clang diagnostic error "-Wc++1z-extensions"
- #endif
- #ifdef INCLUDE_ASSERT_H
- #include <assert.h>
- #endif
- static_assert (2 + 2 == 4, "arithmetic does not work");
- static_assert (2 + 2 == 4);
- ]],
- [[
- static_assert (sizeof (char) == 1, "sizeof does not work");
- static_assert (sizeof (char) == 1);
- ]])],
- [gl_cv_static_assert=$gl_working],
- [gl_cv_static_assert=no])
- CFLAGS=$gl_saved_CFLAGS
- test "$gl_cv_static_assert" != no && break
- done])
+ AS_CASE([$gl_working],
+ [*assert.h*], [CFLAGS="$gl_saved_CFLAGS -DINCLUDE_ASSERT_H"])
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#if defined __clang__ && __STDC_VERSION__ < 202311
+ #pragma clang diagnostic error "-Wc2x-extensions"
+ #pragma clang diagnostic error "-Wc++1z-extensions"
+ #endif
+ #ifdef INCLUDE_ASSERT_H
+ #include <assert.h>
+ #endif
+ static_assert (2 + 2 == 4, "arithmetic does not work");
+ static_assert (2 + 2 == 4);
+ ]],
+ [[
+ static_assert (sizeof (char) == 1, "sizeof does not work");
+ static_assert (sizeof (char) == 1);
+ ]])
+ ],
+ [gl_cv_static_assert=$gl_working],
+ [gl_cv_static_assert=no])
+ CFLAGS=$gl_saved_CFLAGS
+ test "$gl_cv_static_assert" != no && break
+ done
+ ])
GL_GENERATE_ASSERT_H=false
AS_CASE([$gl_cv_static_assert],
@@ -56,7 +57,16 @@ AC_DEFUN([gl_ASSERT_H]
dnl Break the #undef_s apart with a comment so that 'configure' does
dnl not comment them out.
AH_VERBATIM([zzstatic_assert],
-[#if (!defined HAVE_C_STATIC_ASSERT && !defined assert \
+[#if (!(defined __clang__ \
+ ? (defined __cplusplus \
+ ? __cplusplus >= 201703L \
+ : __STDC_VERSION__ >= 202000L && __clang_major__ >= 16) : \
+ defined __GNUC__ \
+ ? (defined __cplusplus \
+ ? __cplusplus >= 201103L && __GNUG__ >= 6 \
+ : __STDC_VERSION__ >= 202000L && __GNUC__ >= 13) : \
+ defined HAVE_C_STATIC_ASSERT) \
+ && !defined assert \
&& (!defined __cplusplus \
|| (__cpp_static_assert < 201411 \
&& __GNUG__ < 6 && __clang_major__ < 6)))
diff --git a/m4/c-bool.m4 b/m4/c-bool.m4
index 13aeae90d5..8ea186d1cf 100644
--- a/m4/c-bool.m4
+++ b/m4/c-bool.m4
@@ -1,5 +1,5 @@
# c-bool.m4
-# serial 1
+# serial 2
dnl Copyright 2022-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -35,7 +35,10 @@ AC_DEFUN([gl_C_BOOL]
dnl define it to a bool expression equal to 1; this is needed in
dnl Sun C++ 5.11 (Oracle Solaris Studio 12.2, 2010) and older.
AH_VERBATIM([zzbool],
-[#ifndef HAVE_C_BOOL
+[#if !(defined __cplusplus ? 1 : \
+ defined __clang__ ? __STDC_VERSION__ >= 202000L && __clang_major__ >= 15
: \
+ defined __GNUC__ ? __STDC_VERSION__ >= 202000L && __GNUC__ >= 13 : \
+ defined HAVE_C_BOOL)
# if !defined __cplusplus && !defined __bool_true_false_are_defined
# if HAVE_STDBOOL_H
# include <stdbool.h>