]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Add configure check for _Static_assert()
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Fri, 6 Sep 2013 13:27:04 +0000 (15:27 +0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Fri, 6 Sep 2013 14:06:19 +0000 (11:06 -0300)
Commit 8efede20ef ("Use _Static_assert") introduced the usage of
_Static_assert(). However, _Static_assert() is a fairly new thing,
since it was introduced only in gcc 4.6. In order to support older
compilers, this patch adds a configure.in test that checks whether
_Static_assert() is usable or not, and adjust the behavior of the
assert_cc() macro accordingly.

configure.ac
libkmod/macro.h

index 40e54cf7ea790fd4c93136786f65460a4590f299..a192c8170b44b00d4f46ba725ddc94db63539bc1 100644 (file)
@@ -52,6 +52,12 @@ AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
 # Check kernel headers
 AC_CHECK_HEADERS_ONCE([linux/module.h])
 
+AC_MSG_CHECKING([whether _Static_assert() is supported])
+AC_COMPILE_IFELSE(
+       [AC_LANG_SOURCE([[_Static_assert(1, "Test");]])],
+        [AC_DEFINE([HAVE_STATIC_ASSERT], [1], [Define if _Static_assert() is available])
+        AC_MSG_RESULT([yes])],
+       [AC_MSG_RESULT([no])])
 
 #####################################################################
 # --with-
index c6ba8556343d760daefc436fbcc202c4b7c2a1db..10392a338cddd4a5a82f81079692503d418d059d 100644 (file)
 
 #include <stddef.h>
 
+#if defined(HAVE_STATIC_ASSERT)
 #define assert_cc(expr) \
        _Static_assert((expr), #expr)
+#else
+#define assert_cc(expr) \
+       do { (void) sizeof(char [1 - 2*!(expr)]); } while(0)
+#endif
 
 #if HAVE_TYPEOF
 #define check_types_match(expr1, expr2)                \