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

Maxim Bublis b at codemonkey.ru
Tue Nov 26 19:46:14 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 |  9 ++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 5f7ed24..37030db 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_CACHE_CHECK([for _Static_assert compiler support],
+    [ac_cv__static_assert],
+    [AC_TRY_COMPILE([],
+        [_Static_assert(1, "The impossible happened.");],
+        ac_cv__static_assert=yes,
+        ac_cv__static_assert=no)])
+if test "${ac_cv__static_assert}" != "no"; then
+    AC_DEFINE([HAVE__STATIC_ASSERT], [1], [Define to 1 if compiler has intrinsic _Static_assert.])
+fi
+
+dnl C++11 static_assert()
+AC_CACHE_CHECK([for static_assert in <cassert>],
+    [ac_cv_static_assert_cxx],
+    [AC_LANG_PUSH([C++])
+     AC_TRY_COMPILE([#include <cassert>],
+        [static_assert(1, "The impossible happened.");],
+        ac_cv_static_assert_cxx=yes,
+        ac_cv_static_assert_cxx=no)
+     AC_LANG_POP([C++])])
+if test "${ac_cv_static_assert_cxx}" != "no"; then
+    AC_DEFINE([HAVE_STATIC_ASSERT_CXX], [1], [Define to 1 if <cassert> defines static_assert.])
+fi
+
 # Windows CE does not have strcoll()
 AC_FUNC_STRCOLL
 
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 26bba5e..5af454e 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)
+#ifndef HAVE__STATIC_ASSERT
 # define _Static_assert(x, s) ((void) sizeof (struct { unsigned:-!(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