Mercurial > gnulib
changeset 17739:3fb7cf1816d1
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.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 07 Aug 2014 17:25:28 -0700 |
parents | 586e46ada98b |
children | be8b85935367 |
files | ChangeLog m4/vararrays.m4 |
diffstat | 2 files changed, 60 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Aug 07 09:52:04 2014 -0700 +++ b/ChangeLog Thu Aug 07 17:25:28 2014 -0700 @@ -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
--- a/m4/vararrays.m4 Thu Aug 07 09:52:04 2014 -0700 +++ b/m4/vararrays.m4 Thu Aug 07 17:25:28 2014 -0700 @@ -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 ])