]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
AC_C__GENERIC: New macro.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 27 Dec 2012 22:34:07 +0000 (14:34 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 27 Dec 2012 22:35:16 +0000 (14:35 -0800)
* NEWS, doc/autoconf.texi (C Compiler): Document it.
* lib/autoconf/c.m4 (AC_C__GENERIC): Implement it.

NEWS
doc/autoconf.texi
lib/autoconf/c.m4

diff --git a/NEWS b/NEWS
index 185ca263da8667d14105e887c1cdf7790ad9b7b8..a4cd3a1cdc80b0e715611157b97a8f5fdadcdcfc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@ GNU Autoconf NEWS - User visible changes.
 
 ** Macros
 
+- New macro AC_C__GENERIC.
+
 - AC_CONFIG_MACRO_DIRS
   New macro, used to declare multiple directories when looking for
   local M4 macros.  This macro overcomes some of the shortfalls in the
index aa948a9036ab5d69b3cad7d90aa9d8c8f15a2866..bcf8f861a5bf9c91fa2b363ce597686229feafd6 100644 (file)
@@ -7434,6 +7434,13 @@ This macro is obsolescent, as current C compilers support @code{const}.
 New programs need not use this macro.
 @end defmac
 
+@defmac AC_C__GENERIC
+@acindex{C__GENERIC}
+@cvindex _Generic
+If the C compiler supports C11-style generic selection using the
+@code{_Generic} keyword, define @code{HAVE_C__GENERIC}.
+@end defmac
+
 @defmac AC_C_RESTRICT
 @acindex{C_RESTRICT}
 @cvindex restrict
index e17df1e871b5ae4129ee80dd24a3977ee76bff32..edc663b492f8b7ae940ae2773de98b66088fada1 100644 (file)
@@ -1690,6 +1690,33 @@ dnl default behavior for universal builds.
 ])# AC_C_BIGENDIAN
 
 
+# AC_C__GENERIC
+# -------------
+# Define HAVE_C__GENERIC if _Generic works, a la C11.
+AN_IDENTIFIER([_Generic], [AC_C__GENERIC])
+AC_DEFUN([AC_C__GENERIC],
+[AC_CACHE_CHECK([for _Generic], ac_cv_c__Generic,
+[AC_COMPILE_IFELSE(
+   [AC_LANG_SOURCE(
+      [[int
+        main (int argc, char **argv)
+        {
+          int a = _Generic (argc, int: argc = 1);
+          int *b = &_Generic (argc, default: argc);
+          char ***c = _Generic (argv, int: argc, default: argv ? &argv : 0);
+          _Generic (1 ? 0 : b, int: a, default: b) = &argc;
+          _Generic (a = 1, default: a) = 3;
+          return a + !b + !c;
+        }
+      ]])],
+   [ac_cv_c__Generic=yes],
+   [ac_cv_c__Generic=no])])
+if test $ac_cv_c__Generic = yes; then
+  AC_DEFINE([HAVE_C__GENERIC], 1,
+           [Define to 1 if C11-style _Generic works.])
+fi
+])# AC_C__GENERIC
+
 # AC_C_INLINE
 # -----------
 # Do nothing if the compiler accepts the inline keyword.