Skip to content

Commit 0c7171b

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 1c41731 commit 0c7171b

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed

configure

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3975,6 +3975,130 @@ else
39753975
fi
39763976
fi
39773977

3978+
# We use C constructs that became invalid in C23. Check if the compiler
3979+
# reports a standard higher than C17, with the flags selected above (so the
3980+
# user can control the language level explicitly to avoid the gcc/clang-only
3981+
# fallback logic below if preferred).
3982+
{ $as_echo "$as_me:$LINENO: checking whether $CC reports a C standard higher than ISO C17" >&5
3983+
$as_echo_n "checking whether $CC reports a C standard higher than ISO C17... " >&6; }
3984+
cat >conftest.$ac_ext <<_ACEOF
3985+
/* confdefs.h. */
3986+
_ACEOF
3987+
cat confdefs.h >>conftest.$ac_ext
3988+
cat >>conftest.$ac_ext <<_ACEOF
3989+
/* end confdefs.h. */
3990+
3991+
int
3992+
main ()
3993+
{
3994+
#if __STDC_VERSION__ > 201710L
3995+
choke me
3996+
#endif
3997+
;
3998+
return 0;
3999+
}
4000+
_ACEOF
4001+
rm -f conftest.$ac_objext
4002+
if { (ac_try="$ac_compile"
4003+
case "(($ac_try" in
4004+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
4005+
*) ac_try_echo=$ac_try;;
4006+
esac
4007+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
4008+
$as_echo "$ac_try_echo") >&5
4009+
(eval "$ac_compile") 2>conftest.er1
4010+
ac_status=$?
4011+
grep -v '^ *+' conftest.er1 >conftest.err
4012+
rm -f conftest.er1
4013+
cat conftest.err >&5
4014+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
4015+
(exit $ac_status); } && {
4016+
test -z "$ac_c_werror_flag" ||
4017+
test ! -s conftest.err
4018+
} && test -s conftest.$ac_objext; then
4019+
POSTC17=no
4020+
else
4021+
$as_echo "$as_me: failed program was:" >&5
4022+
sed 's/^/| /' conftest.$ac_ext >&5
4023+
4024+
POSTC17=yes
4025+
fi
4026+
4027+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4028+
{ $as_echo "$as_me:$LINENO: result: ${POSTC17}" >&5
4029+
$as_echo "${POSTC17}" >&6; }
4030+
4031+
# If a too recent standard was detected with the user's CFLAGS, try asking for
4032+
# C17 with GNU extensions explicitly.
4033+
if test "$POSTC17" = yes; then
4034+
old_CFLAGS="$CFLAGS"
4035+
{ $as_echo "$as_me:$LINENO: checking whether $CC supports -std=gnu17" >&5
4036+
$as_echo_n "checking whether $CC supports -std=gnu17... " >&6; }
4037+
if test "${pgac_cv_prog_cc_cflags__std_gnu17+set}" = set; then
4038+
$as_echo_n "(cached) " >&6
4039+
else
4040+
pgac_save_CFLAGS=$CFLAGS
4041+
CFLAGS="$pgac_save_CFLAGS -std=gnu17"
4042+
ac_save_c_werror_flag=$ac_c_werror_flag
4043+
ac_c_werror_flag=yes
4044+
cat >conftest.$ac_ext <<_ACEOF
4045+
/* confdefs.h. */
4046+
_ACEOF
4047+
cat confdefs.h >>conftest.$ac_ext
4048+
cat >>conftest.$ac_ext <<_ACEOF
4049+
/* end confdefs.h. */
4050+
4051+
int
4052+
main ()
4053+
{
4054+
4055+
;
4056+
return 0;
4057+
}
4058+
_ACEOF
4059+
rm -f conftest.$ac_objext
4060+
if { (ac_try="$ac_compile"
4061+
case "(($ac_try" in
4062+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
4063+
*) ac_try_echo=$ac_try;;
4064+
esac
4065+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
4066+
$as_echo "$ac_try_echo") >&5
4067+
(eval "$ac_compile") 2>conftest.er1
4068+
ac_status=$?
4069+
grep -v '^ *+' conftest.er1 >conftest.err
4070+
rm -f conftest.er1
4071+
cat conftest.err >&5
4072+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
4073+
(exit $ac_status); } && {
4074+
test -z "$ac_c_werror_flag" ||
4075+
test ! -s conftest.err
4076+
} && test -s conftest.$ac_objext; then
4077+
pgac_cv_prog_cc_cflags__std_gnu17=yes
4078+
else
4079+
$as_echo "$as_me: failed program was:" >&5
4080+
sed 's/^/| /' conftest.$ac_ext >&5
4081+
4082+
pgac_cv_prog_cc_cflags__std_gnu17=no
4083+
fi
4084+
4085+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
4086+
ac_c_werror_flag=$ac_save_c_werror_flag
4087+
CFLAGS="$pgac_save_CFLAGS"
4088+
fi
4089+
{ $as_echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_cflags__std_gnu17" >&5
4090+
$as_echo "$pgac_cv_prog_cc_cflags__std_gnu17" >&6; }
4091+
if test x"$pgac_cv_prog_cc_cflags__std_gnu17" = x"yes"; then
4092+
CFLAGS="$CFLAGS -std=gnu17"
4093+
fi
4094+
4095+
if test "$CFLAGS" = "$old_CFLAGS"; then
4096+
{ { $as_echo "$as_me:$LINENO: error: cannot proceed" >&5
4097+
$as_echo "$as_me: error: cannot proceed" >&2;}
4098+
{ (exit 1); exit 1; }; }
4099+
fi
4100+
fi
4101+
39784102
# Some versions of GCC support some additional useful warning flags.
39794103
# Check whether they are supported, and add them to CFLAGS if so.
39804104
# ICC pretends to be GCC but it's lying; it doesn't support these flags,

configure.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,26 @@ else
407407
fi
408408
fi
409409

410+
# We use C constructs that became invalid in C23. Check if the compiler
411+
# reports a standard higher than C17, with the flags selected above (so the
412+
# user can control the language level explicitly to avoid the gcc/clang-only
413+
# fallback logic below if preferred).
414+
AC_MSG_CHECKING([whether $CC reports a C standard higher than ISO C17])
415+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [@%:@if __STDC_VERSION__ > 201710L
416+
choke me
417+
@%:@endif])], [POSTC17=no], [POSTC17=yes])
418+
AC_MSG_RESULT(${POSTC17})
419+
420+
# If a too recent standard was detected with the user's CFLAGS, try asking for
421+
# C17 with GNU extensions explicitly.
422+
if test "$POSTC17" = yes; then
423+
old_CFLAGS="$CFLAGS"
424+
PGAC_PROG_CC_CFLAGS_OPT([-std=gnu17])
425+
if test "$CFLAGS" = "$old_CFLAGS"; then
426+
AC_MSG_ERROR([cannot proceed])
427+
fi
428+
fi
429+
410430
# Some versions of GCC support some additional useful warning flags.
411431
# Check whether they are supported, and add them to CFLAGS if so.
412432
# ICC pretends to be GCC but it's lying; it doesn't support these flags,

0 commit comments

Comments
 (0)