Skip to content

Commit bd98457

Browse files
committed
build: try to use _Static_assert if static_assert is not available
* configure.ac: Check for _Static_assert if static_assert is not available. * static_assert.h [!HAVE_STATIC_ASSERT && HAVE__STATIC_ASSERT] (static_assert): Define to _Static_assert.
1 parent 96ebee2 commit bd98457

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

configure.ac

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,13 +797,31 @@ fi
797797

798798
AC_CACHE_CHECK([for static_assert], [st_cv_have_static_assert],
799799
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <assert.h>]],
800-
[[static_assert(1,"")]])],
800+
[[static_assert(1,"")]]
801+
)
802+
],
801803
[st_cv_have_static_assert=yes],
802-
[st_cv_have_static_assert=no])])
803-
if test "x$st_cv_have_static_assert" = xyes; then
804-
AC_DEFINE([HAVE_STATIC_ASSERT], [1],
805-
[Define to 1 if the system provides static_assert])
806-
fi
804+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
805+
[[_Static_assert(1,"")]]
806+
)
807+
],
808+
[st_cv_have_static_assert=_Static_assert],
809+
[st_cv_have_static_assert=no]
810+
)
811+
]
812+
)
813+
]
814+
)
815+
case "x$st_cv_have_static_assert" in
816+
xyes)
817+
AC_DEFINE([HAVE_STATIC_ASSERT], [1],
818+
[Define to 1 if the system provides static_assert])
819+
;;
820+
x_Static_assert)
821+
AC_DEFINE([HAVE__STATIC_ASSERT], [1],
822+
[Define to 1 if the system provides _Static_assert])
823+
;;
824+
esac
807825

808826
AC_CHECK_LIB([dl], [dladdr], [dl_LIBS='-ldl'], [dl_LIBS=])
809827
if test "x$ac_cv_lib_dl_dladdr" = xyes; then

static_assert.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@
3030

3131
#include "assert.h"
3232

33-
#ifndef HAVE_STATIC_ASSERT
33+
#if defined HAVE_STATIC_ASSERT
34+
35+
/* static_assert is already available */
36+
37+
#elif defined HAVE__STATIC_ASSERT
38+
39+
# undef static_assert
40+
# define static_assert _Static_assert
41+
42+
#else /* !HAVE_STATIC_ASSERT && !HAVE__STATIC_ASSERT */
3443

3544
# define static_assert(expr, message) \
3645
extern int (*strace_static_assert(int))[sizeof(int[2 * !!(expr) - 1])]

0 commit comments

Comments
 (0)