Debian Codegraph @

build-aux/m4/zw_static_assert.m4

raw
1 dnl Written by Zack Weinberg <zackw at panix.com> in 2017.
2 dnl To the extent possible under law, Zack Weinberg has waived all
3 dnl copyright and related or neighboring rights to this work.
4 dnl
5 dnl See https://creativecommons.org/publicdomain/zero/1.0/ for further
6 dnl details.
7 dnl
8 dnl Check for static_assert in <assert.h>; failing that, check for intrinsic
9 dnl support for C11 _Static_assert.
10 dnl assert.h itself is in C89 and does not need to be probed for;
11 dnl moreover, AC_PROG_CC's check for C11 includes _Static_assert (but not
12 dnl static_assert).
13 dnl Some logic borrowed from gnulib's assert_h.m4.
14 dnl 2*2 != 7 is tested in honor of Stanisław Lem.
15 AC_DEFUN([zw_C_STATIC_ASSERT],
16 [AC_REQUIRE([AC_PROG_CC])
17 AC_CACHE_CHECK([for static_assert in assert.h],
18 [zw_cv_c_assert_h_static_assert],
19 [AC_COMPILE_IFELSE(
20 [AC_LANG_PROGRAM([[
21 #undef NDEBUG
22 #include <assert.h>
23 static_assert(2 + 2 == 4, "arithmetic does not work");
24 ]], [[
25 static_assert(sizeof (char) == 1, "sizeof does not work");
26 ]])],
27 [static_assert_true=yes],
28 [static_assert_true=no])
29 AC_COMPILE_IFELSE(
30 [AC_LANG_PROGRAM([[
31 #undef NDEBUG
32 #include <assert.h>
33 static_assert(2 * 2 == 7, "this assertion should fail");
34 ]])],
35 [static_assert_false=no],
36 [static_assert_false=yes])
37 AS_IF([test $static_assert_false$static_assert_true = yesyes],
38 [zw_cv_c_assert_h_static_assert=yes],
39 [zw_cv_c_assert_h_static_assert=no])])
40 AS_IF([test $zw_cv_c_assert_h_static_assert = yes],
41 [AC_DEFINE([HAVE_STATIC_ASSERT_IN_ASSERT_H], 1,
42 [Define if <assert.h> defines static_assert.])],
43 [AC_CACHE_CHECK([for _Static_assert],
44 [zw_cv_c__Static_assert],
45 [AS_IF([test x$ac_prog_cc_stdc = xc11],
46 [zw_cv_c__Static_assert=yes],
47 [AC_COMPILE_IFELSE(
48 [AC_LANG_PROGRAM([[
49 _Static_assert(2 + 2 == 4, "arithmetic does not work");
50 ]], [[
51 _Static_assert(sizeof (char) == 1, "sizeof does not work");
52 ]])],
53 [_Static_assert_true=yes],
54 [_Static_assert_true=no])
55 AC_COMPILE_IFELSE(
56 [AC_LANG_PROGRAM([[
57 _Static_assert(2 * 2 == 7, "this assertion should fail");
58 ]])],
59 [_Static_assert_false=no],
60 [_Static_assert_false=yes])
61 AS_IF([test $static_assert_false$static_assert_true = yesyes],
62 [zw_cv_c__Static_assert=yes],
63 [zw_cv_c__Static_assert=no])])])
64 AS_IF([test $zw_cv_c__Static_assert = yes],
65 [AC_DEFINE([HAVE__STATIC_ASSERT], 1,
66 [Define if the compiler supports the _Static_assert intrinsic.])])
67 ])
68 ])