[vlc-devel] [PATCH] Added check for _Static_assert and C++11 static_assert.
Rémi Denis-Courmont
remi at remlab.net
Mon Nov 25 22:35:58 CET 2013
Le dimanche 24 novembre 2013, 00:23:35 Maxim Bublis a écrit :
> 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
Well, I'm not quite sure how it is possible for the standard C and C++
libraries to disagree on static_assert() (and all the while the C and C++
compilers agree on _Static_assert()...). But I cannot blame you for being
pedantic.
However, please use configure caching when writing compiler tests.
> ---
> 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..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..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
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list