Port better to MSVC

Problems reported by Antonin Décimo in:
https://lists.gnu.org/r/autoconf/2024-04/msg00001.html
* lib/autoconf/c.m4 (_AC_C_C89_TEST_GLOBALS):
Do not test the value of __STDC__.
(_AC_C_C99_TEST_MAIN): Do not test for VLAs.
(_AC_C_C11_OPTIONS): Also test -std:c11.
This commit is contained in:
Paul Eggert 2024-04-25 14:47:20 -07:00
parent 75fe83f9d6
commit e9fee73dba
3 changed files with 21 additions and 12 deletions

7
NEWS
View File

@ -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]

View File

@ -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}.

View File

@ -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 <stddef.h>
#include <stdarg.h>
@ -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
])