[vlc-devel] [PATCH v3] Added check for _Static_assert and C++11 static_assert.

Maxim Bublis b at codemonkey.ru
Sat Nov 23 21:16:35 CET 2013


This patch handles following three cases:
 * compiler doesn't have _Static_assert 
 * standard C library doesn't have static_assert
 * standard C++ library doesn't have static_assert

---
 configure.ac         | 24 ++++++++++++++++++++++++
 include/vlc_fixups.h | 11 +++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5f7ed24..ae9f96e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -554,6 +554,30 @@ static_assert(1, "The impossible happened.");
   AC_MSG_RESULT([no])
 ])
 
+dnl C11 _Static_assert()
+AC_MSG_CHECKING([for _Static_assert compiler support])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([
+_Static_assert(1, "The impossible happened.");
+])], [
+  AC_MSG_RESULT([yes])
+  AC_DEFINE([HAVE__STATIC_ASSERT], [1], [Define to 1 if compiler has intrinsic _Static_assert.])
+], [
+  AC_MSG_RESULT([no])
+])
+
+AC_LANG_PUSH([C++])
+dnl C++11 static_assert()
+AC_MSG_CHECKING([for static_assert in <cassert>])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <cassert>], [
+static_assert(1, "The impossible happened.");
+])], [
+  AC_MSG_RESULT([yes])
+  AC_DEFINE([HAVE_STATIC_ASSERT_CXX], [1], [Define to 1 if <cassert> defines static_assert.])
+], [
+  AC_MSG_RESULT([no])
+])
+AC_LANG_POP([C++])
+
 # Windows CE does not have strcoll()
 AC_FUNC_STRCOLL
 
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 26bba5e..d5e79fe 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -239,8 +239,15 @@ static inline locale_t newlocale(int mask, const char * locale, locale_t base)
 }
 #endif
 
-#if !defined (HAVE_STATIC_ASSERT)
-# define _Static_assert(x, s) ((void) sizeof (struct { unsigned:-!(x); }))
+#ifndef HAVE__STATIC_ASSERT
+# define _Static_assert(x, s) ((void) sizeof (struct { unsinged:-!(x); }))
+#endif
+
+#if !defined(HAVE_STATIC_ASSERT) && !defined(__cplusplus)
+# define static_assert _Static_assert
+#endif
+
+#if !defined(HAVE_STATIC_ASSERT_CXX) && defined(__cplusplus)
 # define static_assert _Static_assert
 #endif
 
-- 
1.8.3.4 (Apple Git-47)




More information about the vlc-devel mailing list