Skip to content

Commit 170e416

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 0305dd3 commit 170e416

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

configure

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5086,6 +5086,83 @@ else
50865086
BITCODE_CXXFLAGS="-O2 $BITCODE_CXXFLAGS"
50875087
fi
50885088

5089+
# We use C constructs that became invalid in C23. Check if the compiler
5090+
# reports a standard higher than C17, with the flags selected above (so the
5091+
# user can control the language level explicitly to avoid the gcc/clang-only
5092+
# fallback logic below if preferred).
5093+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC reports a C standard higher than ISO C17" >&5
5094+
$as_echo_n "checking whether $CC reports a C standard higher than ISO C17... " >&6; }
5095+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5096+
/* end confdefs.h. */
5097+
5098+
int
5099+
main ()
5100+
{
5101+
#if __STDC_VERSION__ > 201710L
5102+
choke me
5103+
#endif
5104+
;
5105+
return 0;
5106+
}
5107+
_ACEOF
5108+
if ac_fn_c_try_compile "$LINENO"; then :
5109+
POSTC17=no
5110+
else
5111+
POSTC17=yes
5112+
fi
5113+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5114+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${POSTC17}" >&5
5115+
$as_echo "${POSTC17}" >&6; }
5116+
5117+
# If a too recent standard was detected with the user's CFLAGS, try asking for
5118+
# C17 with GNU extensions explicitly.
5119+
if test "$POSTC17" = yes; then
5120+
old_CFLAGS="$CFLAGS"
5121+
5122+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -std=gnu17, for CFLAGS" >&5
5123+
$as_echo_n "checking whether ${CC} supports -std=gnu17, for CFLAGS... " >&6; }
5124+
if ${pgac_cv_prog_CC_cflags__std_gnu17+:} false; then :
5125+
$as_echo_n "(cached) " >&6
5126+
else
5127+
pgac_save_CFLAGS=$CFLAGS
5128+
pgac_save_CC=$CC
5129+
CC=${CC}
5130+
CFLAGS="${CFLAGS} -std=gnu17"
5131+
ac_save_c_werror_flag=$ac_c_werror_flag
5132+
ac_c_werror_flag=yes
5133+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5134+
/* end confdefs.h. */
5135+
5136+
int
5137+
main ()
5138+
{
5139+
5140+
;
5141+
return 0;
5142+
}
5143+
_ACEOF
5144+
if ac_fn_c_try_compile "$LINENO"; then :
5145+
pgac_cv_prog_CC_cflags__std_gnu17=yes
5146+
else
5147+
pgac_cv_prog_CC_cflags__std_gnu17=no
5148+
fi
5149+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5150+
ac_c_werror_flag=$ac_save_c_werror_flag
5151+
CFLAGS="$pgac_save_CFLAGS"
5152+
CC="$pgac_save_CC"
5153+
fi
5154+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__std_gnu17" >&5
5155+
$as_echo "$pgac_cv_prog_CC_cflags__std_gnu17" >&6; }
5156+
if test x"$pgac_cv_prog_CC_cflags__std_gnu17" = x"yes"; then
5157+
CFLAGS="${CFLAGS} -std=gnu17"
5158+
fi
5159+
5160+
5161+
if test "$CFLAGS" = "$old_CFLAGS"; then
5162+
as_fn_error $? "cannot proceed" "$LINENO" 5
5163+
fi
5164+
fi
5165+
50895166
# C[XX]FLAGS we determined above will be added back at the end
50905167
user_CFLAGS=$CFLAGS
50915168
CFLAGS=""

configure.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,26 @@ else
451451
BITCODE_CXXFLAGS="-O2 $BITCODE_CXXFLAGS"
452452
fi
453453

454+
# We use C constructs that became invalid in C23. Check if the compiler
455+
# reports a standard higher than C17, with the flags selected above (so the
456+
# user can control the language level explicitly to avoid the gcc/clang-only
457+
# fallback logic below if preferred).
458+
AC_MSG_CHECKING([whether $CC reports a C standard higher than ISO C17])
459+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [@%:@if __STDC_VERSION__ > 201710L
460+
choke me
461+
@%:@endif])], [POSTC17=no], [POSTC17=yes])
462+
AC_MSG_RESULT(${POSTC17})
463+
464+
# If a too recent standard was detected with the user's CFLAGS, try asking for
465+
# C17 with GNU extensions explicitly.
466+
if test "$POSTC17" = yes; then
467+
old_CFLAGS="$CFLAGS"
468+
PGAC_PROG_CC_CFLAGS_OPT([-std=gnu17])
469+
if test "$CFLAGS" = "$old_CFLAGS"; then
470+
AC_MSG_ERROR([cannot proceed])
471+
fi
472+
fi
473+
454474
# C[XX]FLAGS we determined above will be added back at the end
455475
user_CFLAGS=$CFLAGS
456476
CFLAGS=""

0 commit comments

Comments
 (0)