Skip to content

Commit b1b8b8e

Browse files
committed
If a C23 compiler is detected, try asking for C17.
Branches before 16 can't be compiled with a C23 compiler (see deprecation warnings silenced by commit f9a56e7, and non-back-patchable changes made in 16 by commit 1c27d16). Test __STDC_VERSION__, and if it's above C17 then try appending -std=gnu17. The test is done with the user's CFLAGS, so an acceptable language version can also be configured manually that way. This is done in branches 15 and older, back to 9.2, per policy of keeping them buildable with modern tools. Discussion: https://postgr.es/m/87o72eo9iu.fsf%40gentoo.org
1 parent 8851d5c commit b1b8b8e

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

configure

+72
Original file line numberDiff line numberDiff line change
@@ -4366,6 +4366,78 @@ else
43664366
fi
43674367
fi
43684368

4369+
# We use C constructs that became invalid in C23. Check if the compiler
4370+
# reports a standard higher than C17, with the flags selected above (so the
4371+
# user can control the language level explicitly to avoid the gcc/clang-only
4372+
# fallback logic below if preferred).
4373+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC reports a C standard higher than ISO C17" >&5
4374+
$as_echo_n "checking whether $CC reports a C standard higher than ISO C17... " >&6; }
4375+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4376+
/* end confdefs.h. */
4377+
4378+
int
4379+
main ()
4380+
{
4381+
#if __STDC_VERSION__ > 201710L
4382+
choke me
4383+
#endif
4384+
;
4385+
return 0;
4386+
}
4387+
_ACEOF
4388+
if ac_fn_c_try_compile "$LINENO"; then :
4389+
POSTC17=no
4390+
else
4391+
POSTC17=yes
4392+
fi
4393+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4394+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${POSTC17}" >&5
4395+
$as_echo "${POSTC17}" >&6; }
4396+
4397+
# If a too recent standard was detected with the user's CFLAGS, try asking for
4398+
# C17 with GNU extensions explicitly.
4399+
if test "$POSTC17" = yes; then
4400+
old_CFLAGS="$CFLAGS"
4401+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=gnu17" >&5
4402+
$as_echo_n "checking whether $CC supports -std=gnu17... " >&6; }
4403+
if ${pgac_cv_prog_cc_cflags__std_gnu17+:} false; then :
4404+
$as_echo_n "(cached) " >&6
4405+
else
4406+
pgac_save_CFLAGS=$CFLAGS
4407+
CFLAGS="$pgac_save_CFLAGS -std=gnu17"
4408+
ac_save_c_werror_flag=$ac_c_werror_flag
4409+
ac_c_werror_flag=yes
4410+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4411+
/* end confdefs.h. */
4412+
4413+
int
4414+
main ()
4415+
{
4416+
4417+
;
4418+
return 0;
4419+
}
4420+
_ACEOF
4421+
if ac_fn_c_try_compile "$LINENO"; then :
4422+
pgac_cv_prog_cc_cflags__std_gnu17=yes
4423+
else
4424+
pgac_cv_prog_cc_cflags__std_gnu17=no
4425+
fi
4426+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4427+
ac_c_werror_flag=$ac_save_c_werror_flag
4428+
CFLAGS="$pgac_save_CFLAGS"
4429+
fi
4430+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_cc_cflags__std_gnu17" >&5
4431+
$as_echo "$pgac_cv_prog_cc_cflags__std_gnu17" >&6; }
4432+
if test x"$pgac_cv_prog_cc_cflags__std_gnu17" = x"yes"; then
4433+
CFLAGS="$CFLAGS -std=gnu17"
4434+
fi
4435+
4436+
if test "$CFLAGS" = "$old_CFLAGS"; then
4437+
as_fn_error $? "cannot proceed" "$LINENO" 5
4438+
fi
4439+
fi
4440+
43694441
# CFLAGS we determined above will be added back at the end
43704442
user_CFLAGS=$CFLAGS
43714443
CFLAGS=""

configure.in

+20
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,26 @@ else
409409
fi
410410
fi
411411

412+
# We use C constructs that became invalid in C23. Check if the compiler
413+
# reports a standard higher than C17, with the flags selected above (so the
414+
# user can control the language level explicitly to avoid the gcc/clang-only
415+
# fallback logic below if preferred).
416+
AC_MSG_CHECKING([whether $CC reports a C standard higher than ISO C17])
417+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [@%:@if __STDC_VERSION__ > 201710L
418+
choke me
419+
@%:@endif])], [POSTC17=no], [POSTC17=yes])
420+
AC_MSG_RESULT(${POSTC17})
421+
422+
# If a too recent standard was detected with the user's CFLAGS, try asking for
423+
# C17 with GNU extensions explicitly.
424+
if test "$POSTC17" = yes; then
425+
old_CFLAGS="$CFLAGS"
426+
PGAC_PROG_CC_CFLAGS_OPT([-std=gnu17])
427+
if test "$CFLAGS" = "$old_CFLAGS"; then
428+
AC_MSG_ERROR([cannot proceed])
429+
fi
430+
fi
431+
412432
# CFLAGS we determined above will be added back at the end
413433
user_CFLAGS=$CFLAGS
414434
CFLAGS=""

0 commit comments

Comments
 (0)