]> Savannah Git Hosting - gnulib.git/commitdiff
assert-h, stdbool: Allow mixed use of gcc/g++ and clang/clang++ again.
authorBruno Haible <bruno@clisp.org>
Tue, 29 Oct 2024 12:48:36 +0000 (13:48 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 12 Nov 2024 00:45:13 +0000 (01:45 +0100)
* 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.

ChangeLog
m4/assert_h.m4
m4/c-bool.m4

index 76f078ca84189ac305a448965972b57b7a2a3d33..bf41e8e3c91dd30c2771b8a281fd497dd590de7e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-10-29  Bruno Haible  <bruno@clisp.org>
+
+       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.
+
 2024-10-26  Paul Eggert  <eggert@cs.ucla.edu>
 
        posix_memalign-tests: fix message typo
index a73e45f06419ef531edcf4e525c1e0e285c56d6f..66f20fb262a627a48604ef5f31f1ebcb6760b269 100644 (file)
@@ -9,32 +9,33 @@ dnl From Paul Eggert.
 AC_DEFUN([gl_ASSERT_H],
 [
   AC_CACHE_CHECK([for static_assert], [gl_cv_static_assert],
-    [gl_save_CFLAGS=$CFLAGS
+    [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_save_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_save_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],
@@ -47,6 +48,10 @@ AC_DEFUN([gl_ASSERT_H],
 
   dnl The "zz" puts this toward config.h's end, to avoid potential
   dnl collisions with other definitions.
+  dnl Hardcode the known configuration results for GCC and clang, so that
+  dnl a configuration made with the C compiler works also with the C++ compiler
+  dnl and vice versa.
+  dnl The seemingly redundant parentheses are necessary for MSVC 14.
   dnl #undef assert so that programs are not tempted to use it without
   dnl specifically including assert.h.
   dnl #undef __ASSERT_H__ so that on IRIX, when programs later include
@@ -54,7 +59,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)))
index 44fba3c012fcf7677e8bb0452cd761dbe12b3b2e..844529bb7d0eae5b1b2e76712051e3a10fa521a6 100644 (file)
@@ -27,12 +27,23 @@ AC_DEFUN([gl_C_BOOL],
   dnl The "zz" puts this toward config.h's end, to avoid potential
   dnl collisions with other definitions.
   dnl If 'bool', 'true' and 'false' do not work, arrange for them to work.
-  dnl In C, this means including <stdbool.h> if it is not already included.
+  dnl Hardcode the known configuration results for GCC and clang, so that
+  dnl a configuration made with the C compiler works also with the C++ compiler
+  dnl and vice versa.
+  dnl The seemingly redundant parentheses are necessary for MSVC 14.
+  dnl "Arrange for them to work", in C, means including <stdbool.h> if it is
+  dnl not already included.
   dnl However, if the preprocessor mistakenly treats 'true' as 0,
   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>