]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Port better to MSVC
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 25 Apr 2024 21:47:20 +0000 (14:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 30 Apr 2024 17:33:37 +0000 (10:33 -0700)
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.

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

diff --git a/NEWS b/NEWS
index 01a058aa7a99065957b4f60a36c9f8fe60e11582..3d968c4ca95fa5041f5a4ed743e18cf67cf8addd 100644 (file)
--- 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]
 
index 186c033b352ea0288453c4cf065622503bb9d1cb..0fd820562d65554709ce01f9cfccfeaa0530bb4b 100644 (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}.
index d8eab7bbd6775b89c06b1ba19349ba3946cd7095..d410f8bc2acb1a2918b0d37f1a94f2d4fc2b99c1 100644 (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
 ])