summaryrefslogtreecommitdiffstats
path: root/gl/m4/assert_h.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/assert_h.m4')
-rw-r--r--gl/m4/assert_h.m493
1 files changed, 59 insertions, 34 deletions
diff --git a/gl/m4/assert_h.m4 b/gl/m4/assert_h.m4
index abba4fa3..e77524ca 100644
--- a/gl/m4/assert_h.m4
+++ b/gl/m4/assert_h.m4
@@ -1,40 +1,43 @@
1# assert-h.m4 1# assert_h.m4
2dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. 2# serial 5
3dnl Copyright (C) 2011-2025 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
7dnl This file is offered as-is, without any warranty.
6 8
7dnl From Paul Eggert. 9dnl From Paul Eggert.
8 10
9AC_DEFUN([gl_ASSERT_H], 11AC_DEFUN([gl_ASSERT_H],
10[ 12[
11 AC_CACHE_CHECK([for static_assert], [gl_cv_static_assert], 13 AC_CACHE_CHECK([for static_assert], [gl_cv_static_assert],
12 [gl_save_CFLAGS=$CFLAGS 14 [gl_saved_CFLAGS=$CFLAGS
13 for gl_working in "yes, a keyword" "yes, an <assert.h> macro"; do 15 for gl_working in "yes, a keyword" "yes, an <assert.h> macro"; do
14 AS_CASE([$gl_working], 16 AS_CASE([$gl_working],
15 [*assert.h*], [CFLAGS="$gl_save_CFLAGS -DINCLUDE_ASSERT_H"]) 17 [*assert.h*], [CFLAGS="$gl_saved_CFLAGS -DINCLUDE_ASSERT_H"])
16 18 AC_COMPILE_IFELSE(
17 AC_COMPILE_IFELSE( 19 [AC_LANG_PROGRAM(
18 [AC_LANG_PROGRAM( 20 [[#if defined __clang__ && __STDC_VERSION__ < 202311
19 [[#if defined __clang__ && __STDC_VERSION__ < 202311 21 #pragma clang diagnostic error "-Wc2x-extensions"
20 #pragma clang diagnostic error "-Wc2x-extensions" 22 #pragma clang diagnostic error "-Wc++1z-extensions"
21 #pragma clang diagnostic error "-Wc++17-extensions" 23 #endif
22 #endif 24 #ifdef INCLUDE_ASSERT_H
23 #ifdef INCLUDE_ASSERT_H 25 #include <assert.h>
24 #include <assert.h> 26 #endif
25 #endif 27 static_assert (2 + 2 == 4, "arithmetic does not work");
26 static_assert (2 + 2 == 4, "arithmetic does not work"); 28 static_assert (2 + 2 == 4);
27 static_assert (2 + 2 == 4); 29 ]],
28 ]], 30 [[
29 [[ 31 static_assert (sizeof (char) == 1, "sizeof does not work");
30 static_assert (sizeof (char) == 1, "sizeof does not work"); 32 static_assert (sizeof (char) == 1);
31 static_assert (sizeof (char) == 1); 33 ]])
32 ]])], 34 ],
33 [gl_cv_static_assert=$gl_working], 35 [gl_cv_static_assert=$gl_working],
34 [gl_cv_static_assert=no]) 36 [gl_cv_static_assert=no])
35 CFLAGS=$gl_save_CFLAGS 37 CFLAGS=$gl_saved_CFLAGS
36 test "$gl_cv_static_assert" != no && break 38 test "$gl_cv_static_assert" != no && break
37 done]) 39 done
40 ])
38 41
39 GL_GENERATE_ASSERT_H=false 42 GL_GENERATE_ASSERT_H=false
40 AS_CASE([$gl_cv_static_assert], 43 AS_CASE([$gl_cv_static_assert],
@@ -46,20 +49,42 @@ AC_DEFUN([gl_ASSERT_H],
46 gl_NEXT_HEADERS([assert.h])]) 49 gl_NEXT_HEADERS([assert.h])])
47 50
48 dnl The "zz" puts this toward config.h's end, to avoid potential 51 dnl The "zz" puts this toward config.h's end, to avoid potential
49 dnl collisions with other definitions. #undef assert so that 52 dnl collisions with other definitions.
50 dnl programs are not tempted to use it without specifically 53 dnl Hardcode the known configuration results for GCC and clang, so that
51 dnl including assert.h. Break the #undef apart with a comment 54 dnl a configuration made with the C compiler works also with the C++ compiler
52 dnl so that 'configure' does not comment it out. 55 dnl and vice versa.
56 dnl The seemingly redundant parentheses are necessary for MSVC 14.
57 dnl #undef assert so that programs are not tempted to use it without
58 dnl specifically including assert.h.
59 dnl #undef __ASSERT_H__ so that on IRIX, when programs later include
60 dnl <assert.h>, this include actually defines assert.
61 dnl Break the #undef_s apart with a comment so that 'configure' does
62 dnl not comment them out.
53 AH_VERBATIM([zzstatic_assert], 63 AH_VERBATIM([zzstatic_assert],
54[#if (!defined HAVE_C_STATIC_ASSERT && !defined assert \ 64[#if (!(defined __clang__ \
65 ? (defined __cplusplus \
66 ? __cplusplus >= 201703L \
67 : __STDC_VERSION__ >= 202000L && __clang_major__ >= 16 \
68 && !defined __sun) \
69 : (defined __GNUC__ \
70 ? (defined __cplusplus \
71 ? __cplusplus >= 201103L && __GNUG__ >= 6 \
72 : __STDC_VERSION__ >= 202000L && __GNUC__ >= 13 \
73 && !defined __sun) \
74 : defined HAVE_C_STATIC_ASSERT)) \
75 && !defined assert \
55 && (!defined __cplusplus \ 76 && (!defined __cplusplus \
56 || (__cpp_static_assert < 201411 \ 77 || (__cpp_static_assert < 201411 \
57 && __GNUG__ < 6 && __clang_major__ < 6))) 78 && __GNUG__ < 6 && __clang_major__ < 6)))
58 #include <assert.h> 79 #include <assert.h>
59 #undef/**/assert 80 #undef/**/assert
81 #ifdef __sgi
82 #undef/**/__ASSERT_H__
83 #endif
60 /* Solaris 11.4 <assert.h> defines static_assert as a macro with 2 arguments. 84 /* Solaris 11.4 <assert.h> defines static_assert as a macro with 2 arguments.
61 We need it also to be invocable with a single argument. */ 85 We need it also to be invocable with a single argument.
62 #if defined __sun && (__STDC_VERSION__ - 0 >= 201112L) && !defined __cplusplus 86 Haiku 2022 <assert.h> does not define static_assert at all. */
87 #if (__STDC_VERSION__ - 0 >= 201112L) && !defined __cplusplus
63 #undef/**/static_assert 88 #undef/**/static_assert
64 #define static_assert _Static_assert 89 #define static_assert _Static_assert
65 #endif 90 #endif