1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

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 f9a56e72, and non-back-patchable
changes made in 16 by commit 1c27d16e).  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
This commit is contained in:
Thomas Munro
2024-11-27 15:43:18 +13:00
parent 88a16b3dbb
commit f00c401c65
2 changed files with 97 additions and 0 deletions

View File

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