]> Savannah Git Hosting - gnulib.git/commitdiff
vararrays: modernize AC_C_VARARRAYS for C11
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 8 Aug 2014 00:25:28 +0000 (17:25 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 8 Aug 2014 00:25:52 +0000 (17:25 -0700)
This backports a change I recently made to Autoconf.
* m4/vararrays.m4 (AC_C_VARARRAYS): Define __STDC_NO_VLA__ if
VLAs are not supported, as this is what C11 does.  The old macro
HAVE_C_VARARRAYS is still defined if they are supported, but is
now obsolescent.  Also, check for VLA bug in GCC 3.4.3.

ChangeLog
m4/vararrays.m4

index e8dd13e278bc559bb372d087fd7c8e092ddbec54..386520bf83a1b21cdd3da6b08cecf06194f21a31 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2014-08-07  Paul Eggert  <eggert@cs.ucla.edu>
+
+       vararrays: modernize AC_C_VARARRAYS for C11
+       This backports a change I recently made to Autoconf.
+       * m4/vararrays.m4 (AC_C_VARARRAYS): Define __STDC_NO_VLA__ if
+       VLAs are not supported, as this is what C11 does.  The old macro
+       HAVE_C_VARARRAYS is still defined if they are supported, but is
+       now obsolescent.  Also, check for VLA bug in GCC 3.4.3.
+
 2014-08-07  Alessandro Degano  <degano@cern.ch>  (tiny change)
 
        relocatable-prog-wrapper: port gettext to OS X 10.8 + GCC 4.8.1
index 9d597094d2203818276529b4c59c879f4c071267..cbda525c75e3e4545d1efdc9393c76616dd125bd 100644 (file)
@@ -1,6 +1,6 @@
 # Check for variable-length arrays.
 
-# serial 4
+# serial 5
 
 # From Paul Eggert
 
@@ -9,17 +9,60 @@
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# This is a copy of AC_C_VARARRAYS from a recent development version
+# of Autoconf.  It replaces Autoconf's version, or for pre-2.61 autoconf
+# it defines the macro that Autoconf lacks.
 AC_DEFUN([AC_C_VARARRAYS],
 [
   AC_CACHE_CHECK([for variable-length arrays],
     ac_cv_c_vararrays,
-    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
-         [],
-         [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])],
-       ac_cv_c_vararrays=yes,
-       ac_cv_c_vararrays=no)])
-  if test $ac_cv_c_vararrays = yes; then
-    AC_DEFINE([HAVE_C_VARARRAYS], [1],
+    [AC_EGREP_CPP([defined],
+       [#ifdef __STDC_NO_VLA__
+       defined
+       #endif
+       ],
+       [ac_cv_c_vararrays='no: __STDC_NO_VLA__ is defined'],
+       [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[/* Test for VLA support.  This test is partly inspired
+                 from examples in the C standard.  Use at least two VLA
+                 functions to detect the GCC 3.4.3 bug described in:
+                 http://lists.gnu.org/archive/html/bug-gnulib/2014-08/msg00014.html
+                 */
+              #ifdef __STDC_NO_VLA__
+               syntax error;
+              #else
+                extern int n;
+                int B[100];
+                int fvla (int m, int C[m][m]);
+
+                int
+                simple (int count, int all[static count])
+                {
+                  return all[count - 1];
+                }
+
+                int
+                fvla (int m, int C[m][m])
+                {
+                  typedef int VLA[m][m];
+                  VLA x;
+                  int D[m];
+                  static int (*q)[m] = &B;
+                  int (*s)[n] = q;
+                  return C && &x[0][0] == &D[0] && &D[0] == s[0];
+                }
+              #endif
+              ]])],
+         [ac_cv_c_vararrays=yes],
+         [ac_cv_c_vararrays=no])])])
+  if test "$ac_cv_c_vararrays" = yes; then
+    dnl This is for compatibility with Autoconf 2.61-2.69.
+    AC_DEFINE([HAVE_C_VARARRAYS], 1,
       [Define to 1 if C supports variable-length arrays.])
+  elif test "$ac_cv_c_vararrays" = no; then
+    AC_DEFINE([__STDC_NO_VLA__], 1,
+      [Define to 1 if C does not support variable-length arrays, and
+       if the compiler does not already define this.])
   fi
 ])