autoconf: Restore compatibility with older std-gnu11.m4.

https://github.com/libsdl-org/autoconf/commit/2d0f19d84ddb13412382674fd48e6fc5c2875d0e

From 2d0f19d84ddb13412382674fd48e6fc5c2875d0e Mon Sep 17 00:00:00 2001
From: Zack Weinberg <[EMAIL REDACTED]>
Date: Mon, 21 Dec 2020 14:04:22 -0500
Subject: [PATCH] Restore compatibility with older std-gnu11.m4.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Gnulib’s std-gnu11.m4 backports C11 and C++11 detection to autoconf
2.69.  It does this by replacing the definitions of AC_PROC_CC and
AC_PROG_CXX and most of their subroutines.  In particular, it replaces
the definitions of _AC_PROG_CC_C11, _AC_PROG_CC_C99, and _AC_C_STD_TRY,
but it does *not* replace the definition of _AC_PROG_CC_C89.

Autoconf commit 131d8c69f31dc6fc8dc93abe1096d52d1fe19fd3 changed the
calling convention of _AC_C_STD_TRY, and changed the internal
definitions of _AC_PROG_CC_C{11,99,89} to match.  If std-gnu11.m4 is
in use, our _AC_PROG_CC_C89 calls their _AC_C_STD_TRY with the new
calling convention, and this produces a syntactically invalid
configure script.  (This is is fortunate: it could easily have been a
runtime malfunction that only manifested with compilers that only
implement C89, and then we might not have noticed the problem for
years.)

Gnulib commit a3b3fc85e3e632374811b27cb2111e50fa177e36 makes
std-gnu11.m4 do nothing when used with autoconf >=2.70, but older
versions of the file will circulate for years to come, so this patch
works around the problem in autoconf.  It does this by renaming all of
the internal macros involved with C and C++ standard edition
detection, *except* _AC_PROG_CC_C89.  AC_PROG_CC now calls
_AC_PROG_CC_STDC_EDITION, which loops over all supported editions
calling _AC_PROG_CC_STDC_EDITION_TRY, which uses the data provided by
the existing _AC_C_C${edition}_TEST_PROGRAM macros and a new set of
macros called _AC_C_C${edition}_OPTIONS to perform the test for that
edition of the standard.  Similarly, AC_PROG_CXX calls
_AC_PROG_CXX_STDCXX_EDITION, which loops calling
_AC_PROG_CXX_STDCXX_EDITION_TRY, which uses data from
_AC_CXX_CXX${edition}_TEST_PROGRAM and _AC_CXX_CXX${edition}_OPTIONS.

_AC_PROG_CC_C89 is the only macro from the old set that we still
define, and its definition is reverted to what std-gnu11.m4 expects it
to be.  Nothing in Autoconf proper uses it anymore.

foreign.at grows a test to verify that the compatibility stub version
of _AC_PROG_CC_C89 does its job.  Since this is now the third test
involving an embedded copy of a third-party macro, I broke them all
out of foreign.at to separate files in test/data/.

In addition to fixing the breakage, this patch should make it easier
to extend C / C++ standard edition detection in the future, by getting
rid of the if-else chains in AC_PROG_CC/CXX and by disentangling the
lists of command-line options to test from the logic.

I also changed the manual to suggest people refer to the variables
‘ac_prog_cc_stdc’ and ‘ac_prog_cxx_stdcxx’ to learn which edition
of the C and C++ standards are selected; these are much easier to
work with than the ac_cv_prog_cc_cNN cache variables.

* lib/autoconf/c.m4 (_AC_C_STD_TRY, _AC_PROG_CC_C99, _AC_PROG_CC_C11)
  (_AC_CXX_STD_TRY, _AC_PROG_CXX_CXX98, _AC_PROG_CXX_CXX11): Remove macro.

  (_AC_C_C89_OPTIONS, _AC_C_C99_OPTIONS, _AC_C_C11_OPTIONS)
  (_AC_PROG_CC_STDC_EDITION, _AC_PROG_CC_STDC_EDITION_TRY)
  (_AC_CXX_CXX98_OPTIONS, _AC_CXX_CXX11_OPTIONS)
  (_AC_PROG_CXX_STDCXX_EDITION, _AC_PROG_CXX_STDCXX_EDITION_TRY): New macros.

  (_AC_PROG_CC_C89): Convert to compatibility stub for std-gnu11.m4.

  (AC_PROG_CC): Use _AC_PROG_CC_STDC_EDITION.
  (AC_PROG_CXX): Use _AC_PROG_CXX_STDCXX_EDITION.

* tests/data/ax_prog_cc_for_build_v18.m4
* tests/data/ax_prog_cxx_for_build_v3.m4
* tests/data/gnulib_std_gnu11_2020_08_17.m4: New files.
* tests/foreign.at (AX_PROG_CC_FOR_BUILD, AX_PROG_CXX_FOR_BUILD):
  Remove embedded copy of ax_prog_cc_for_build_v18.m4,
  ax_prog_cxx_for_build_v3.m4 respectively.
  (gnulib-std-gnu11.m4): New test.
* tests/local.mk: Distribute tests/data/*.m4.

* doc/autoconf.texi (AC_PROG_CC, AC_PROG_CXX): Document use of
  ac_prog_cc_stdc / ac_prog_cxx_stdcxx, respectively, to tell which
  edition of the C / C++ standards are selected, instead of looking
  through a series of cache variables with awkward definitions.
---
 doc/autoconf.texi                         |  45 +-
 lib/autoconf/c.m4                         | 444 +++++++-----
 tests/data/ax_prog_cc_for_build_v18.m4    | 139 ++++
 tests/data/ax_prog_cxx_for_build_v3.m4    | 110 +++
 tests/data/gnulib_std_gnu11_2020_08_17.m4 | 824 ++++++++++++++++++++++
 tests/foreign.at                          | 215 +-----
 tests/local.mk                            |   7 +-
 7 files changed, 1384 insertions(+), 400 deletions(-)
 create mode 100644 tests/data/ax_prog_cc_for_build_v18.m4
 create mode 100644 tests/data/ax_prog_cxx_for_build_v3.m4
 create mode 100644 tests/data/gnulib_std_gnu11_2020_08_17.m4

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 5e17280e..b1bd8be6 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -7453,7 +7453,6 @@ makes this invalid.  That is why Autoconf stopped issuing
 @evindex CFLAGS
 @ovindex CC
 @ovindex CFLAGS
-@caindex prog_cc_stdc
 Determine a C compiler to use.
 
 If the environment variable @code{CC} is set, its value will be taken as
@@ -7485,21 +7484,15 @@ default.  (It is important to use this construct rather than a normal
 assignment, so that @code{CFLAGS} can still be overridden by the
 person building the package.  @xref{Preset Output Variables}.)
 
-If necessary, options are added to @code{CC} to enable support for ISO
-Standard C features with extensions, preferring the newest C standard
-that is supported.  Currently the newest standard Autoconf knows how to
-detect support for is ISO C 2011.  After calling this macro you can
-check whether the C compiler has been set to accept Standard C by
-inspecting cache variables.  If @code{ac_cv_prog_cc_c11} is set to any
-value other than @samp{no} (including the empty string), then @code{CC}
-can compile code as standard C 2011, and this mode has been enabled.
-Otherwise, if @code{ac_cv_prog_cc_c99} is set to any value other than
-@samp{no} (including the empty string), then @code{CC} can compile code
-as standard C 1999, and this mode has been enabled.  Otherwise, if
-@code{ac_cv_prog_cc_c89} is set to any value other than @samp{no}
-(including the empty string), then @code{CC} can compile code as
-standard C 1989, and this mode has been enabled.  Finally, if all
-three variables are set to @samp{no}, then @code{CC} cannot compile
+If necessary, options are added to @code{CC} to enable support for
+ISO Standard C features with extensions, preferring the newest edition
+of the C standard that is supported.  Currently the newest edition
+Autoconf knows how to detect support for is ISO C 2011.  After calling
+this macro you can check whether the C compiler has been set to accept
+standard C by inspecting the shell variable @code{ac_prog_cc_stdc}.
+Its value will be @samp{c11}, @samp{c99}, or @samp{c89}, respectively,
+if the C compiler has been set to use the 2011, 1999, or 1990 edition of
+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
@@ -7890,17 +7883,15 @@ assignment, so that @code{CXXFLAGS} can still be overridden by the
 person building the package.  @xref{Preset Output Variables}.)
 
 If necessary, options are added to @code{CXX} to enable support for
-ISO Standard C++ features with extensions.  ISO C++ 2011 is preferred
-if the compiler supports it.  After calling this macro, you can check
-whether the C++ compiler has been set to accept standard C++ by
-inspecting cache variables.  If @code{ac_cv_prog_cxx_cxx11} is set to
-any value other than @samp{no} (including the empty string), then
-@code{CXX} can compile code as standard C++ 2011, and this mode has
-been enabled.  Otherwise, if @code{ac_cv_prog_cxx_cxx98} is set to
-any value other than @samp{no} (including the empty string), then
-@code{CXX} can compile code as standard C++ 1998, and this mode has
-been enabled.  Finally, if both variables are set to @samp{no}, then
-@code{CXX} cannot compile standard C++ at all.
+ISO Standard C++ features with extensions, preferring the newest edition
+of the C++ standard that is supported.  Currently the newest edition
+Autoconf knows how to detect support for is ISO C++ 2011.  After calling
+this macro, you can check whether the C++ compiler has been set to
+accept standard C++ by inspecting the shell variable @code{ac_prog_cc_stdc}.
+Its value will be @samp{cxx11} or @samp{cxx98}, respectively,
+if the C++ compiler has been set to use the 2011 or 1990 edition of 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 value of @code{__cplusplus} and a representative sample of the
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 14240460..7ad6b4f7 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -498,19 +498,7 @@ else
   GCC=
 fi
 _AC_PROG_CC_G
-dnl
-dnl Set ac_prog_cc_stdc to the supported C version.
-dnl Also set the documented variable ac_cv_prog_cc_stdc;
-dnl its name was chosen when it was cached, but it is no longer cached.
-_AC_PROG_CC_C11([ac_prog_cc_stdc=c11
-		 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11],
-  [_AC_PROG_CC_C99([ac_prog_cc_stdc=c99
-		    ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
-     [_AC_PROG_CC_C89([ac_prog_cc_stdc=c89
-		       ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
-		      [ac_prog_cc_stdc=no
-		       ac_cv_prog_cc_stdc=no])])])
-dnl
+_AC_PROG_CC_STDC_EDITION
 AC_LANG_POP(C)dnl
 ])# AC_PROG_CC
 
@@ -745,13 +733,7 @@ else
   GXX=
 fi
 _AC_PROG_CXX_G
-_AC_PROG_CXX_CXX11([ac_prog_cxx_stdcxx=cxx11
-		    ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11
-		    ac_cv_prog_cxx_cxx98=$ac_cv_prog_cxx_cxx11],
-   [_AC_PROG_CXX_CXX98([ac_prog_cxx_stdcxx=cxx98
-		        ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98],
-		       [ac_prog_cxx_stdcxx=no
-		        ac_cv_prog_cxx_stdcxx=no])])
+_AC_PROG_CXX_STDCXX_EDITION
 AC_LANG_POP(C++)dnl
 ])# AC_PROG_CXX
 
@@ -1496,114 +1478,170 @@ main (int argc, char **argv)
 ]])])
 
 
-# _AC_C_STD_TRY(STANDARD, TEST-PROGRAM-HOLDER, OPTION-LIST,
-#		ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
-# --------------------------------------------------------------
-# Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
-# by trying to compile the program in the shell variable TEST-PROGRAM-HOLDER.
-# Caller is responsible for making sure this variable has been initialized.
-# If compilation fails in the default mode, try again with each compiler
-# option in the space-separated OPTION-LIST; if one helps, append it to CC.
-# If eventually successful, run ACTION-IF-AVAILABLE, else ACTION-IF-UNAVAILABLE.
-AC_DEFUN([_AC_C_STD_TRY],
+# _AC_C_C89_OPTIONS
+# -----------------
+# Whitespace-separated list of options that might put the C compiler
+# into a mode conforming to ISO C1990 with extensions.  Do not try
+# "strictly conforming" modes (e.g. gcc's -std=c90); they break some
+# systems' header files.  If more than one option is needed, put
+# shell quotes around the group.
+#
+# AIX circa 2003         -qlanglvl=extc89
+# old AIX                -qlanglvl=ansi
+# Ultrix, OSF/1, Tru64   -std
+# HP-UX 10.20 and later  -Ae
+# HP-UX older versions   -Aa -D_HPUX_SOURCE
+# SVR4                   -Xc -D__EXTENSIONS__
+m4_define([_AC_C_C89_OPTIONS], [
+    -qlanglvl=extc89
+    -qlanglvl=ansi
+    -std
+    -Ae
+    "-Aa -D_HPUX_SOURCE"
+    "-Xc -D__EXTENSIONS__"
+])
+
+
+# _AC_C_C99_OPTIONS
+# -----------------
+# Whitespace-separated list of options that might put the C compiler
+# into a mode conforming to ISO C1999 with extensions.  Do not try
+# "strictly conforming" modes (e.g. gcc's -std=c99); they break some
+# systems' header files.  If more than one option is needed, put
+# shell quotes around the group.
+#
+# GCC, Clang    -std=gnu99
+# Intel ICC     -std=c99, -c99 (deprecated)
+#   Note: because -std=c99 puts GCC in strictly conforming mode,
+#   this option must be tested *after* -std=gnu99.
+# IRIX          -c99
+# Tru64         -c99
+# IBM XL C      -qlanglvl=extc1x (V12.1; does not pass C11 test)
+# IBM XL C      -qlanglvl=extc99 (pre-V12.1)
+# HP cc         -AC99
+# Solaris       -D_STDC_C99=
+#   Note: acc's -xc99 option uses linker magic to define the external
+#   symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
+#   behavior for C library functions.  This is not wanted here,
+#   because it means that a single module compiled with -xc99 alters
+#   C runtime behavior for the entire program, not for just the
+#   module.  Instead, define the (private) symbol _STDC_C99, which
+#   suppresses a bogus failure in <stdbool.h>.  The resulting compiler
+#   passes the test case here, and that's good enough.
+#   For more, please see the thread starting at:
+#   https://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
+m4_define([_AC_C_C99_OPTIONS], [
+    -std=gnu99
+    -std=c99
+    -c99
+    -qlanglvl=extc1x
+    -qlanglvl=extc99
+    -AC99
+    -D_STDC_C99=
+])
+
+
+# _AC_C_C11_OPTIONS
+# -----------------
+# Whitespace-separated list of options that might put the C compiler
+# into a mode conforming to ISO C2011 with extensions.  Do not try
+# "strictly conforming" modes (e.g. gcc's -std=c11); they break some
+# systems' header files.  If more than one option is needed, put
+# shell quotes around the group.
+#
+# GCC, Clang    -std=gnu11
+#
+# 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
+# -qlanglvl=extc1x as xlc with IBM XL C V16.1 (the latest version as
+# of August 2020) does not pass the C11 test.  Instead, try extc1x when
+# compiling the C99 test instead, since it enables _Static_assert and
+# _Noreturn, which is a win.
+m4_define([_AC_C_C11_OPTIONS], [
+    -std=gnu11
+])
+
+
+# _AC_PROG_CC_STDC_EDITION_TRY(EDITION)
+# -------------------------------------
+# Subroutine of _AC_PROG_CC_STDC_EDITION.  Not to be called directly.
+#
+# Check whether the C compiler accepts features of EDITION of the
+# C standard.  EDITION should be a two-digit year (e.g. 89, 99, 11).
+# (FIXME: Switch to four-digit years for futureproofing.)
+# This is done by compiling the test program defined by
+# _AC_C_C{EDITION}_TEST_PROGRAM, first with no additional
+# command-line options, and then with each of the options
+# in the space-separated list defined by _AC_C_C{EDITION}_OPTIONS.
+#
+# If we find a way to make the test program compile, set cache variable
+# ac_cv_prog_cc_cEDITION to the options required (if any), and add those
+# options to $CC.  Set shell variable ac_prog_cc_stdc to `cEDITION',
+# and set shell variable ac_cv_prog_cc_stdc to the options required.
+# (Neither of these variables is AC_SUBSTed.  ac_cv_prog_cc_stdc used
+# to be a cache variable and is preserved with this name for backward
+# compatibility.)  Otherwise, ac_cv_prog_cc_cEDITION is set to `no'
+# and the other variables are not changed.
+#
+# If ac_prog_cc_stdc is already set to a value other than `no',
+# the shell code produced by this macro does nothing.  This is so
+# _AC_PROG_CC_STDC_EDITION can use m4_map to iterate through
+# all the editions.
+AC_DEFUN([_AC_PROG_CC_STDC_EDITION_TRY],
 [AC_LANG_ASSERT([C])]dnl
-[AC_MSG_CHECKING([for $CC option to enable ]dnl
-m4_translit($1, [c], [C])[ features])
-AC_CACHE_VAL([ac_cv_prog_cc_$1],
-[ac_cv_prog_cc_$1=no
+[AC_REQUIRE([_AC_C_C$1_TEST_PROGRAM])]dnl
+[AS_IF([test x$ac_prog_cc_stdc = xno],
+[AC_MSG_CHECKING([for $CC option to enable C$1 features])
+AC_CACHE_VAL([ac_cv_prog_cc_c$1],
+[ac_cv_prog_cc_c$1=no
 ac_save_CC=$CC
-AC_LANG_CONFTEST([AC_LANG_DEFINES_PROVIDED][$][$2])
-for ac_arg in '' $3
+AC_LANG_CONFTEST([AC_LANG_DEFINES_PROVIDED][$][ac_c_conftest_c$1_program])
+for ac_arg in '' m4_normalize(m4_defn([_AC_C_C$1_OPTIONS]))
 do
   CC="$ac_save_CC $ac_arg"
-  _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
-  test "x$ac_cv_prog_cc_$1" != "xno" && break
+  _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_c$1=$ac_arg])
+  test "x$ac_cv_prog_cc_c$1" != "xno" && break
 done
 rm -f conftest.$ac_ext
-CC=$ac_save_CC
-])# AC_CACHE_VAL
-ac_prog_cc_stdc_options=
-AS_CASE(["x$ac_cv_prog_cc_$1"],
-  [x],   [AC_MSG_RESULT([none needed])],
-  [xno], [AC_MSG_RESULT([unsupported])],
-   [ac_prog_cc_stdc_options=" $ac_cv_prog_cc_$1"
-    CC="$CC$ac_prog_cc_stdc_options"
-    AC_MSG_RESULT([$ac_cv_prog_cc_$1])])
-AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$4], [$5])
-])# _AC_C_STD_TRY
-
-
-# _AC_PROG_CC_C89 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
-# ----------------------------------------------------------------
-# If the C compiler is not in ANSI C89 (ISO C90) mode by default, try
-# to add an option to output variable CC to make it so.
+CC=$ac_save_CC])
+AS_IF([test "x$ac_cv_prog_cc_c$1" = xno],
+  [AC_MSG_RESULT([unsupported])],
+  [AS_IF([test "x$ac_cv_prog_cc_c$1" = x],
+    [AC_MSG_RESULT([none needed])],
+    [AC_MSG_RESULT([$ac_cv_prog_cc_c$1])
+     CC="$CC $ac_cv_prog_cc_c$1"])
+  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c$1
+  ac_prog_cc_stdc=c$1])])
+])
+
+
+# _AC_PROG_CC_STDC_EDITION
+# ------------------------
+# Detect the most recent edition of the ISO C standard that is
+# supported by the C compiler.  Add command-line options to $CC, if
+# necessary, to enable support for this edition.  Set the shell
+# variable ac_prog_cc_stdc to indicate the edition.
+AC_DEFUN([_AC_PROG_CC_STDC_EDITION],
+[ac_prog_cc_stdc=no
+m4_map([_AC_PROG_CC_STDC_EDITION_TRY], [[11], [99], [89]])])
+
+
+# _AC_PROG_CC_C89(ACTION-IF-SUPPORTED, ACTION-IF-NOT-SUPPORTED)
+# -------------------------------------------------------------
+# Obsolete internal macro.  No longer used by Autoconf itself, but
+# preserved for backward compatibility with pre-December 2020 versions
+# of Gnulib's std-gnu11.m4, which replaced the entire definition of
+# AC_PROG_CC *except* for this macro.  Can be removed once everyone is
+# using Autoconf 2.70 and/or a current std-gnu11.m4.
 AC_DEFUN([_AC_PROG_CC_C89],
-[AC_REQUIRE([_AC_C_C89_TEST_PROGRAM])]dnl
-[_AC_C_STD_TRY([c89], [ac_c_conftest_c89_program],
-dnl Don't try gcc -ansi; that turns off useful extensions and
-dnl breaks some systems' header files.
-dnl AIX circa 2003	-qlanglvl=extc89
-dnl old AIX		-qlanglvl=ansi
-dnl Ultrix, OSF/1, Tru64	-std
-dnl HP-UX 10.20 and later	-Ae
-dnl HP-UX older versions	-Aa -D_HPUX_SOURCE
-dnl SVR4			-Xc -D__EXTENSIONS__
-[-qlanglvl=extc89 -qlanglvl=ansi -std \
-	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"], [$1], [$2])[]dnl
-])# _AC_PROG_CC_C89
-
-
-# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
-# ----------------------------------------------------------------
-# If the C compiler is not in ISO C99 mode by default, try to add an
-# option to output variable CC to make it so.
-AC_DEFUN([_AC_PROG_CC_C99],
-[AC_REQUIRE([_AC_C_C99_TEST_PROGRAM])]dnl
-[_AC_C_STD_TRY([c99], [ac_c_conftest_c99_program],
-dnl Try
-dnl GCC		-std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
-dnl IBM XL C	-qlanglvl=extc1x (V12.1; does not pass C11 test)
-dnl IBM XL C	-qlanglvl=extc99
-dnl		(pre-V12.1; unused restrictive mode: -qlanglvl=stdc99)
-dnl HP cc	-AC99
-dnl Intel ICC	-std=c99, -c99 (deprecated)
-dnl IRIX	-c99
-dnl Solaris	-D_STDC_C99=
-dnl		cc's -xc99 option uses linker magic to define the external
-dnl		symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
-dnl		behavior for C library functions.  This is not wanted here,
-dnl		because it means that a single module compiled with -xc99
-dnl		alters C runtime behavior for the entire program, not for
-dnl		just the module.  Instead, define the (private) symbol
-dnl		_STDC_C99, which suppresses a bogus failure in <stdbool.h>.
-dnl		The resulting compiler passes the test case here, and that's
-dnl		good enough.  For more, please see the thread starting at:
-dnl           https://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
-dnl Tru64	-c99
-dnl with extended modes being tried first.
-[[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc1x -qlanglvl=extc99]], [$1], [$2])[]dnl
-])# _AC_PROG_CC_C99
-
-
-# _AC_PROG_CC_C11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
-# ----------------------------------------------------------------
-# If the C compiler is not in ISO C11 mode by default, try to add an
-# option to output variable CC to make it so.
-AC_DEFUN([_AC_PROG_CC_C11],
-[AC_REQUIRE([_AC_C_C11_TEST_PROGRAM])]dnl
-[_AC_C_STD_TRY([c11], [ac_c_conftest_c11_program],
-dnl Try
-dnl GCC		-std=gnu11 (unused restrictive mode: -std=c11)
-dnl with extended modes being tried first.
-dnl
-dnl For IBM XL C for AIX V16.1 or later, '-std=gnu11' should work if
-dnl the user configured with CC='xlclang'.  Otherwise, do not try
-dnl -qlanglvl=extc1x as xlc with IBM XL C V16.1 (the latest version as
-dnl of August 2020) does not pass the C11 test.  Instead, try extc1x when
-dnl compiling the C99 test instead, since it enables _Static_assert and
-dnl _Noreturn, which is a win.
-[[-std=gnu11]], [$1], [$2])[]dnl
-])# _AC_PROG_CC_C11
+[AC_REQUIRE([_AC_C_C89_TEST_GLOBALS])]dnl
+[AC_REQUIRE([_AC_C_C89_TEST_MAIN])]dnl
+[_AC_C_STD_TRY([c89],
+  [$ac_c_conftest_c89_globals], [$ac_c_conftest_c89_main],
+  m4_quote(m4_normalize(m4_defn([_AC_C_C89_OPTIONS]))),
+  [$1],
+  [$2])])
+
 
 
 # AC_PROG_CC_C89
@@ -2633,78 +2671,112 @@ main (int argc, char **argv)
 "
 ]])])
 
+# _AC_CXX_CXX98_OPTIONS
+# ---------------------
+# Whitespace-separated list of options that might put the C++ compiler
+# into a mode conforming to ISO C++ 1998 with extensions.  Do not try
+# "strictly conforming" modes (e.g. gcc's -std=c++98); they break some
+# systems' header files.  If more than one option is needed, put
+# shell quotes around the group.
+#
+# GCC           -std=gnu++98
+# Intel ICC     -std=c++98
+#   Note: because -std=c++98 puts GCC in strictly conforming mode,
+#   this option must be tested *after* -std=gnu++98.
+# IBM XL C      -qlanglvl=extended
+# HP aC++       -AA
+# Solaris       N/A (default)
+# Tru64         N/A (default, but -std gnu could be used)
+m4_define([_AC_CXX_CXX98_OPTIONS], [
+    -std=gnu++98
+    -std=c++98
+    -qlanglvl=extended
+    -AA
+])
 
-# _AC_CXX_STD_TRY(STANDARD, TEST-PROGRAM-HOLDER, OPTION-LIST,
-#		  ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
-# ----------------------------------------------------------------
-# Check whether the C++ compiler accepts features of STANDARD (e.g `cxx98',
-# `cxx11') by trying to compile the program in the shell variable
-# TEST-PROGRAM-HOLDER.  Caller is responsible for making sure this variable
-# has been initialized.  If compilation fails in the default mode, try again
-# with each compiler option in the space-separated OPTION-LIST; if one helps,
-# append it to CXX.  If eventually successful, run ACTION-IF-AVAILABLE, else
-# ACTION-IF-UNAVAILABLE.
+# _AC_CXX_CXX11_OPTIONS
+# ---------------------
+# Whitespace-separated list of options that might put the C++ compiler
+# into a mode conforming to ISO C++ 2011 with extensions.  Do not try
+# "strictly conforming" modes (e.g. gcc's -std=c++11); they break some
+# systems' header files.  If more than one option is needed, put
+# shell quotes around the group.
+#
+# GCC           -std=gnu++11, -std=gnu++0x
+# Intel ICC     -std=c++11, -std=c++0x
+#   Note: because -std=c++11 puts GCC in strictly conforming mode,
+#   these options must be tested *after* -std=gnu++11.
+# IBM XL C      -qlanglvl=extended0x (pre-V12.1)
+# HP aC++       -AA
+# Solaris       N/A (no support)
+# Tru64         N/A (no support)
+m4_define([_AC_CXX_CXX11_OPTIONS], [
+    -std=gnu++11
+    -std=gnu++0x
+    -std=c++11
+    -std=c++0x
+    -qlanglvl=extended0x
+    -AA
+])
 
-AC_DEFUN([_AC_CXX_STD_TRY],
+# _AC_PROG_CXX_STDCXX_EDITION_TRY(EDITION)
+# ----------------------------------------
+# Subroutine of _AC_PROG_CXX_STDCXX_EDITION.  Not to be called directly.
+#
+# Check whether the C++ compiler accepts features of EDITION of the
+# C++ standard.  EDITION should be a two-digit year (e.g. 98, 11).
+# (FIXME: Switch to four-digit years for futureproofing.)
+# This is done by compiling the test program defined by
+# _AC_C_CXX{EDITION}_TEST_PROGRAM, first with no additional
+# command-line options, and then with each of the options
+# in the space-separated list defined by _AC_C_CXX{EDITION}_OPTIONS.
+#
+# If we find a way to make the test program compile, set cache variable
+# ac_cv_prog_cxx_cxxEDITION to the options required (if any), and add those
+# options to $CXX.  Set shell variable ac_prog_cxx_stdcxx to `cxxEDITION',
+# and set shell variable ac_cv_prog_cxx_stdcxx to the options required.
+# (Neither of these variables is AC_SUBSTed.  ac_cv_prog_cxx_stdcxx used
+# to be a cache variable and is preserved with this name for backward
+# compatibility.)  Otherwise, ac_cv_prog_cxx_cxxEDITION is set to `no'
+# and the other variables are not changed.
+#
+# If ac_prog_cxx_stdcxx is already set to a value other than `no',
+# the shell code produced by this macro does nothing.  This is so
+# _AC_PROG_CXX_STDCXX_EDITION can use m4_map to iterate through
+# all the editions.
+AC_DEFUN([_AC_PROG_CXX_STDCXX_EDITION_TRY],
 [AC_LANG_ASSERT([C++])]dnl
-[AC_MSG_CHECKING([for $CXX option to enable ]dnl
-m4_translit([$1], [a-wxyz], [A-W+YZ])[ features])
+[AC_REQUIRE([_AC_CXX_CXX$1_TEST_PROGRAM])]dnl
+[AS_IF([test x$ac_prog_cxx_stdcxx = xno],
+[AC_MSG_CHECKING([for $CXX option to enable C++$1 features])
 AC_CACHE_VAL(ac_cv_prog_cxx_$1,
 [ac_cv_prog_cxx_$1=no
 ac_save_CXX=$CXX
-AC_LANG_CONFTEST([AC_LANG_DEFINES_PROVIDED][$][$2])
-for ac_arg in '' $3
+AC_LANG_CONFTEST([AC_LANG_DEFINES_PROVIDED][$][ac_cxx_conftest_cxx$1_program])
+for ac_arg in '' m4_normalize(m4_defn([_AC_CXX_CXX$1_OPTIONS]))
 do
   CXX="$ac_save_CXX $ac_arg"
-  _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_$1=$ac_arg])
-  test "x$ac_cv_prog_cxx_$1" != "xno" && break
+  _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_cxx$1=$ac_arg])
+  test "x$ac_cv_prog_cxx_cxx$1" != "xno" && break
 done
 rm -f conftest.$ac_ext
-CXX=$ac_save_CXX
-])# AC_CACHE_VAL
-ac_prog_cxx_stdcxx_options=
-AS_CASE(["x$ac_cv_prog_cxx_$1"],
-  [x],   [AC_MSG_RESULT([none needed])],
-  [xno], [AC_MSG_RESULT([unsupported])],
-   [ac_prog_cxx_stdcxx_options=" $ac_cv_prog_cxx_$1"
-    CXX=$CXX$ac_prog_cxx_stdcxx_options
-    AC_MSG_RESULT([$ac_cv_prog_cxx_$1])])
-AS_IF([test "x$ac_cv_prog_cxx_$1" != xno], [$4], [$5])
-])# _AC_CXX_STD_TRY
-
-# _AC_PROG_CXX_CXX98 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
-# -------------------------------------------------------------------
-# If the C++ compiler is not in ISO C++98 mode by default, try to add
-# an option to output variable CXX to make it so.
-AC_DEFUN([_AC_PROG_CXX_CXX98],
-[AC_REQUIRE([_AC_CXX_CXX98_TEST_PROGRAM])]dnl
-[_AC_CXX_STD_TRY([cxx98], [ac_cxx_conftest_cxx98_program],
-dnl Try
-dnl GCC		-std=gnu++98 (unused restrictive mode: -std=c++98)
-dnl IBM XL C	-qlanglvl=extended
-dnl HP aC++	-AA
-dnl Intel ICC	-std=gnu++98
-dnl Solaris	N/A (default)
-dnl Tru64	N/A (default, but -std gnu could be used)
-dnl with extended modes being tried first.
-[[-std=gnu++98 -std=c++98 -qlanglvl=extended -AA]], [$1], [$2])[]dnl
-])# _AC_PROG_CXX_CXX98
-
-# _AC_PROG_CXX_CXX11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
-# -------------------------------------------------------------------
-# If the C++ compiler is not in ISO CXX11 mode by default, try to add
-# an option to output variable CXX to make it so.
-AC_DEFUN([_AC_PROG_CXX_CXX11],
-[AC_REQUIRE([_AC_CXX_CXX11_TEST_PROGRAM])]dnl
-[_AC_CXX_STD_TRY([cxx11], [ac_cxx_conftest_cxx11_program],
-dnl Try
-dnl GCC		-std=gnu++11 (unused restrictive mode: -std=c++11) [and 0x variants]
-dnl IBM XL C	-qlanglvl=extended0x
-dnl		(pre-V12.1; unused restrictive mode: -qlanglvl=stdcxx11)
-dnl HP aC++	-AA
-dnl Intel ICC	-std=c++11 -std=c++0x
-dnl Solaris	N/A (no support)
-dnl Tru64	N/A (no support)
-dnl with extended modes being tried first.
-[[-std=gnu++11 -std=c++11 -std=gnu++0x -std=c++0x -qlanglvl=extended0x -AA]], [$1], [$2])[]dnl
-])# _AC_PROG_CXX_CXX11
+CXX=$ac_save_CXX])
+AS_IF([test "x$ac_cv_prog_cxx_cxx$1" = xno],
+  [AC_MSG_RESULT([unsupported])],
+  [AS_IF([test "x$ac_cv_prog_cxx_cxx$1" = x],
+    [AC_MSG_RESULT([none needed])],
+    [AC_MSG_RESULT([$ac_cv_prog_cxx_cxx$1])
+     CXX="$CXX $ac_cv_prog_cxx_cxx$1"])
+  ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx$1
+  ac_prog_cxx_stdcxx=cxx$1])])
+])
+
+# _AC_PROG_CXX_STDCXX_EDITION
+# ---------------------------
+# Detect the most recent edition of the ISO C++ standard that is
+# supported by the C++ compiler.  Add command-line options to $CXX,
+# if necessary, to enable support for this edition.  Set the shell
+# variable ac_prog_cxx_stdcxx to indicate the edition.
+AC_DEFUN([_AC_PROG_CXX_STDCXX_EDITION],
+[ac_prog_cxx_stdcxx=no
+m4_map([_AC_PROG_CXX_STDCXX_EDITION_TRY], [[11], [98]])])
diff --git a/tests/data/ax_prog_cc_for_build_v18.m4 b/tests/data/ax_prog_cc_for_build_v18.m4
new file mode 100644
index 00000000..f7410d74
--- /dev/null
+++ b/tests/data/ax_prog_cc_for_build_v18.m4
@@ -0,0 +1,139 @@
+# ===========================================================================
+#   https://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_PROG_CC_FOR_BUILD
+#
+# DESCRIPTION
+#
+#   This macro searches for a C compiler that generates native executables,
+#   that is a C compiler that surely is not a cross-compiler. This can be
+#   useful if you have to generate source code at compile-time like for
+#   example GCC does.
+#
+#   The macro sets the CC_FOR_BUILD and CPP_FOR_BUILD macros to anything
+#   needed to compile or link (CC_FOR_BUILD) and preprocess (CPP_FOR_BUILD).
+#   The value of these variables can be overridden by the user by specifying
+#   a compiler with an environment variable (like you do for standard CC).
+#
+#   It also sets BUILD_EXEEXT and BUILD_OBJEXT to the executable and object
+#   file extensions for the build platform, and GCC_FOR_BUILD to `yes' if
+#   the compiler we found is GCC. All these variables but GCC_FOR_BUILD are
+#   substituted in the Makefile.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Paolo Bonzini <bonzini@gnu.org>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+#serial 18
+
+AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD])
+AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_PROG_CPP])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+
+dnl Use the standard macros, but make them use other variable names
+dnl
+pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl
+pushdef([ac_cv_prog_cc_c89], ac_cv_build_prog_cc_c89)dnl
+pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl
+pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl
+pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl
+pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl
+pushdef([ac_cv_c_compiler_gnu], ac_cv_build_c_compiler_gnu)dnl
+pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl
+pushdef([ac_cv_objext], ac_cv_build_objext)dnl
+pushdef([ac_exeext], ac_build_exeext)dnl
+pushdef([ac_objext], ac_build_objext)dnl
+pushdef([CC], CC_FOR_BUILD)dnl
+pushdef([CPP], CPP_FOR_BUILD)dnl
+pushdef([GCC], GCC_FOR_BUILD)dnl
+push

(Patch may be truncated, please check the link at the top of this post.)