linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add configure check for _Static_assert()
@ 2013-08-28 15:33 Thomas Petazzoni
  2013-08-29  3:55 ` Lucas De Marchi
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Petazzoni @ 2013-08-28 15:33 UTC (permalink / raw)
  To: linux-modules; +Cc: thomas.petazzoni

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.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 configure.ac    | 6 ++++++
 libkmod/macro.h | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/configure.ac b/configure.ac
index 40e54cf..cbe12f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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 is _Static_assert() is available])
+	 AC_MSG_RESULT([yes])],
+	[AC_MSG_RESULT([no])])
 
 #####################################################################
 # --with-
diff --git a/libkmod/macro.h b/libkmod/macro.h
index c6ba855..5992026 100644
--- a/libkmod/macro.h
+++ b/libkmod/macro.h
@@ -21,8 +21,12 @@
 
 #include <stddef.h>
 
+#if defined(HAVE_STATIC_ASSERT)
 #define assert_cc(expr) \
 	_Static_assert((expr), #expr)
+#else
+#define assert_cc(expr)
+#endif
 
 #if HAVE_TYPEOF
 #define check_types_match(expr1, expr2)		\
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-09-06 12:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-28 15:33 [PATCH] Add configure check for _Static_assert() Thomas Petazzoni
2013-08-29  3:55 ` Lucas De Marchi
2013-08-29  7:49   ` Thomas Petazzoni
2013-08-29 20:19     ` Lucas De Marchi
2013-09-06 12:58     ` Lucas De Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).