Project

General

Profile

Feature #475 ยป 0060-Check-C23-nullptr-usability-as-a-sentinel.patch

Marko Lindqvist, 04/19/2024 05:08 PM

View differences:

m4/c23.m4
# Check for the presence of C23 features.
# Check for C23 nullptr, and define FREECIV_HAVE_C23_NULLPTR if it's available
# Check for C23 nullptr that can be passed as sentinel
# and define FREECIV_HAVE_C23_NULLPTR if such is available
#
AC_DEFUN([FC_C23_NULLPTR],
[
AC_LANG_PUSH([C])
AC_CHECK_HEADERS([stddef])
AC_CHECK_HEADERS([stddef.h])
AC_CACHE_CHECK([for C23 nullptr], [ac_cv_c23_nullptr],
[AC_LINK_IFELSE([AC_LANG_PROGRAM(
[[#ifdef HAVE_STDDEF
#include <stddef>
#endif]],
[[ int *var = nullptr; ]])],
[ac_cv_c23_nullptr=yes], [ac_cv_c23_nullptr=no])])
[_cflags_="$CFLAGS"
CFLAGS="$EXTRA_DEBUG_CFLAGS $CFLAGS"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
void sentinental(...) __attribute__((__sentinel__(0)));]],
[[ sentinental(nullptr); ]])],
[ac_cv_c23_nullptr=yes], [ac_cv_c23_nullptr=no])]
CFLAGS="$_cflags_")
if test "x${ac_cv_c23_nullptr}" = "xyes" ; then
AC_DEFINE([FREECIV_HAVE_C23_NULLPTR], [1], [C23 nullptr available])
fi
meson.build
pub_conf_data.set('FREECIV_HAVE_LIBZSTD', 1)
endif
# Check for c23 nullptr that can be passed as sentinel
if c_compiler.compiles('''
#include <stddef>
int main(void) { int *var = nullptr; return 0; }''',
#include <stddef.h>
void sentinental(...) __attribute__((__sentinel__(0)));
void caller(void) { sentinental(nullptr); }''',
name: 'c23 nullptr',
include_directories: include_directories(cross_inc_path))
include_directories: include_directories(cross_inc_path),
args: ['-Wformat'])
pub_conf_data.set('FREECIV_HAVE_C23_NULLPTR', 1)
endif
    (1-1/1)