]> granicus.if.org Git - strace/commitdiff
build: try to use _Static_assert if static_assert is not available
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 27 Apr 2018 07:19:52 +0000 (07:19 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 27 Apr 2018 07:19:52 +0000 (07:19 +0000)
* configure.ac: Check for _Static_assert if static_assert
is not available.
* static_assert.h [!HAVE_STATIC_ASSERT && HAVE__STATIC_ASSERT]
(static_assert): Define to _Static_assert.

configure.ac
static_assert.h

index fb9053a5fc0e8d98fae066491d2a8b751b347af1..b2a4e4922dfa454cc412d4e5d669a20d5ca719ff 100644 (file)
@@ -797,13 +797,31 @@ fi
 
 AC_CACHE_CHECK([for static_assert], [st_cv_have_static_assert],
               [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <assert.h>]],
-                                               [[static_assert(1,"")]])],
+                                               [[static_assert(1,"")]]
+                                              )
+                              ],
                               [st_cv_have_static_assert=yes],
-                              [st_cv_have_static_assert=no])])
-if test "x$st_cv_have_static_assert" = xyes; then
-       AC_DEFINE([HAVE_STATIC_ASSERT], [1],
-                 [Define to 1 if the system provides static_assert])
-fi
+                              [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+                                                               [[_Static_assert(1,"")]]
+                                                              )
+                                              ],
+                                              [st_cv_have_static_assert=_Static_assert],
+                                              [st_cv_have_static_assert=no]
+                                             )
+                              ]
+                             )
+              ]
+             )
+case "x$st_cv_have_static_assert" in
+       xyes)
+               AC_DEFINE([HAVE_STATIC_ASSERT], [1],
+                         [Define to 1 if the system provides static_assert])
+               ;;
+       x_Static_assert)
+               AC_DEFINE([HAVE__STATIC_ASSERT], [1],
+                         [Define to 1 if the system provides _Static_assert])
+               ;;
+esac
 
 AC_CHECK_LIB([dl], [dladdr], [dl_LIBS='-ldl'], [dl_LIBS=])
 if test "x$ac_cv_lib_dl_dladdr" = xyes; then
index 1c58e7da5b934ab9ccdb88a195ff9ff3468b7328..e942f79355c37f48db6272688857055a88d51534 100755 (executable)
 
 #include "assert.h"
 
-#ifndef HAVE_STATIC_ASSERT
+#if defined HAVE_STATIC_ASSERT
+
+/* static_assert is already available */
+
+#elif defined HAVE__STATIC_ASSERT
+
+# undef static_assert
+# define static_assert _Static_assert
+
+#else /* !HAVE_STATIC_ASSERT && !HAVE__STATIC_ASSERT */
 
 # define static_assert(expr, message) \
        extern int (*strace_static_assert(int))[sizeof(int[2 * !!(expr) - 1])]