[vlc-devel] [PATCH] Fixed static assertion availability checking.

Maxim Bublis b at codemonkey.ru
Fri Nov 15 09:28:27 CET 2013


This patch fixes static assertion availability checking.
It seems like some compilers (like Clang) do not define static_assert
in <assert.h>, but define _Static_assert as it was called in C1x draft.

---
 configure.ac         | 11 +++++++++++
 include/vlc_fixups.h |  5 ++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 59352b8..80c9ffe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -554,6 +554,17 @@ static_assert(1, "The impossible happened.");
   AC_MSG_RESULT([no])
 ])
 
+dnl C11 _Static_assert()
+AC_MSG_CHECKING([for _Static_assert in assert.h])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <assert.h>], [
+_Static_assert(1, "The impossible happened.");
+])], [
+  AC_MSG_RESULT([yes])
+  AC_DEFINE([HAVE__STATIC_ASSERT], [1], [Define to 1 if <assert.h> defines _Static_assert.])
+], [
+  AC_MSG_RESULT([no])
+])
+
 # Windows CE does not have strcoll()
 AC_FUNC_STRCOLL
 
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 26bba5e..6c15311 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -239,8 +239,11 @@ static inline locale_t newlocale(int mask, const char * locale, locale_t base)
 }
 #endif
 
-#if !defined (HAVE_STATIC_ASSERT)
+#if !defined (HAVE__STATIC_ASSERT)
 # define _Static_assert(x, s) ((void) sizeof (struct { unsigned:-!(x); }))
+#endif
+
+#if !defined (HAVE_STATIC_ASSERT)
 # define static_assert _Static_assert
 #endif
 
-- 
Maxim Bublis




More information about the vlc-devel mailing list