I don't think that proposed patch would work as expected by users.For example, if compiler supports by default C17 and user specified AC_C_STANDARD_VERSION([c89 c99 c11]) then tests would finish with C17 enabled. Moreover, if user stated AC_C_STANDARD_VERSION([c89]), and C89 must be the only accepted version, the tests would finish with the same C17 support enabled. If C11 is enabled by default, it would be enabled regardless what is specified by AC_C_STANDARD_VERSION.
The problem is the checks are written in forward-compatible way, so C89 check would succeed with C11. The current implementation does not check whether C99 would fail if C89 is requested and does not try to find compiler options to *minimize* supported C version.
This wouldn't work for the original problem: detection of C++-style comments by force enabling C89-only to check that sources still could be compiled with C89 compiler.
-- Evgeny On 11.10.2023 10:43, Niels Möller wrote:
Niels Möller <nisse@xxxxxxxxxxxxxx> writes:Updated patch below.How do we move this forward? I think we first need to settle the user-visible part, i.e., how AC_C_STANDARD_VERSION should work (and if that's a good name). Latest patch aims for the following, which seems reasonable to me: * Single argument, white-space separated list of C language versions, in order of preference. Known versions being c89, c99, c11 (upper- or lower-case). * Error on unknown version, error on empty (space-only) argument. * Error if used after AC_PROG_CC, or used multiple times. The effect is to test, in order, if the C compiler supports the given language version, or can be made to support it by adding additional flags to ${CC}. Default behavior is unchanged, and equivalent to AC_C_STANDARD_VERSION([c11 c99 c89]) I'd be happy to sign FSF copyright assignment forms, if required. Regards, /Nielsdiff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index 77ff1af8..adb718f3 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -1561,6 +1561,26 @@ m4_define([_AC_C_C11_OPTIONS], [ -std=gnu11 ])+# _AC_C_CHECK_STANDARD_VERSION+# ---------------------------- +# Translate C version c89, c99, c11 to just the numeric year, +# and raise an error for unknown versions. +AC_DEFUN([_AC_C_CHECK_STANDARD_VERSION], [dnl +m4_case(m4_translit([$1], [C], [c]), [c89], 89, [c99], 99, [c11], 11, +[m4_fatal([Unknown C language revision $1], 1)])dnl +]) + +# AC_C_STANDARD_VERSION(VERSIONS) +# ------------------------------- +# Specifies a whitespace separated list of wanted C versions, in order +# of preference, e.g., AC_C_STANDARD_VERSION([c99 c89]) +AC_DEFUN([AC_C_STANDARD_VERSION], [ + m4_ifdef([_AC_C_STANDARD_VERSION_LIST], + [m4_fatal([AC_PROG_CC_STANDARD_EDITION used after AC_PROG_CC], 1)]) + m4_ifblank([$1], [m4_fatal([C language revision not specified], 1)]) + m4_define([_AC_C_STANDARD_VERSION_LIST], + [m4_map_args_w([$1],[_AC_C_CHECK_STANDARD_VERSION(], [)], [,])]) +])# _AC_PROG_CC_STDC_EDITION_TRY(EDITION)# ------------------------------------- @@ -1623,7 +1643,8 @@ AS_IF([test "x$ac_cv_prog_cc_c$1" = xno], # 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]])]) +m4_define_default([_AC_C_STANDARD_VERSION_LIST], [[11], [99], [89]]) +m4_map([_AC_PROG_CC_STDC_EDITION_TRY], [_AC_C_STANDARD_VERSION_LIST])])# _AC_PROG_CC_C89(ACTION-IF-SUPPORTED, ACTION-IF-NOT-SUPPORTED)
Attachment:
OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key
Attachment:
OpenPGP_signature.asc
Description: OpenPGP digital signature