diff --git a/NEWS b/NEWS index 01a058aa..3d968c4c 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,13 @@ GNU Autoconf NEWS - User visible changes. * Noteworthy changes in release ?.? (????-??-??) [?] +** Backward incompatibilities + +*** AC_PROG_CC no longer tests for VLAs, or whether __STDC__ is defined. + This ports better to MSVC, which does not support variable length + arrays and does not define __STDC__. Although C99 requires VLAs, + they are optional in C11 and later. Programs can use AC_C_VARARRAYS + and __STDC_NO_VLA__ to use VLAs if available. * Noteworthy changes in release 2.72 (2023-12-22) [release] diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 186c033b..0fd82056 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -7444,9 +7444,14 @@ the C standard, and @samp{no} if the compiler does not support compiling standard C at all. The tests for standard conformance are not comprehensive. They test the -values of @code{__STDC__} and @code{__STDC_VERSION__}, and a +value of @code{__STDC_VERSION__}, and a representative sample of the language features added in each version of -the C standard. They do not test the C standard library, because the C +the C standard. They do not examine @code{__STDC__} +because some compilers by default leave it undefined. +They do not test for variable-length arrays, +a C99 feature that was made optional in C11; +if you need to use this feature when available, use @code{AC_C_VARARRAYS}. +They do not test the C standard library, because the C compiler might be generating code for a ``freestanding environment'' (in which most of the standard library is optional). If you need to know whether a particular C standard header exists, use @code{AC_CHECK_HEADER}. diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index d8eab7bb..d410f8bc 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -1120,12 +1120,8 @@ AC_DEFUN([_AC_C_C89_TEST_GLOBALS], [m4_divert_text([INIT_PREPARE], [[# Test code for whether the C compiler supports C89 (global declarations) ac_c_conftest_c89_globals=' -/* Does the compiler advertise C89 conformance? - Do not test the value of __STDC__, because some compilers set it to 0 - while being otherwise adequately conformant. */ -#if !defined __STDC__ -# error "Compiler does not advertise C89 conformance" -#endif +/* Do not test the value of __STDC__, because some compilers define it to 0 + or do not define it, while otherwise adequately conforming. */ #include #include @@ -1337,13 +1333,12 @@ ac_c_conftest_c99_main=' ni.number = 58; - int dynamic_array[ni.number]; - dynamic_array[0] = argv[0][0]; - dynamic_array[ni.number - 1] = 543; + // Do not test for VLAs, as some otherwise-conforming compilers lack them. + // C code should instead use __STDC_NO_VLA__; see Autoconf manual. // work around unused variable warnings ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\'' - || dynamic_array[ni.number - 1] != 543); + || ni.number != 58); ' ]])]) @@ -1553,6 +1548,7 @@ m4_define([_AC_C_C99_OPTIONS], [ # shell quotes around the group. # # GCC, Clang -std=gnu11 +# MSVC -std:c11 # # For IBM XL C for AIX V16.1 or later, '-std=gnu11' should work if # the user configured with CC='xlclang'. Otherwise, do not try @@ -1562,6 +1558,7 @@ m4_define([_AC_C_C99_OPTIONS], [ # _Noreturn, which is a win. m4_define([_AC_C_C11_OPTIONS], [ -std=gnu11 + -std:c11 ])