From: Stefan Metzmacher Date: Wed, 4 Mar 2026 15:39:10 +0000 (+0100) Subject: lib/replace: add BUILD_ASSERT() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efda214cb03bb4716b5fe0beb13ef007d9cf9a68;p=thirdparty%2Fsamba.git lib/replace: add BUILD_ASSERT() This uses _Static_assert() from C11... Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/lib/replace/replace.h b/lib/replace/replace.h index 78f44a8878a..538d1f45b27 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -484,6 +484,12 @@ int rep_dlclose(void *handle); #endif #endif +#ifdef HAVE__STATIC_ASSERT +# define BUILD_ASSERT(x) _Static_assert((x), #x) +#else +# define BUILD_ASSERT(x) +#endif + #if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF) #define vdprintf rep_vdprintf int rep_vdprintf(int fd, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); diff --git a/lib/replace/wscript b/lib/replace/wscript index 4621d90a70a..be2a6ae674f 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -38,6 +38,27 @@ def configure(conf): conf.DEFINE('HAVE_LIBREPLACE', 1) conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1) + conf.CHECK_CODE(''' + _Static_assert(sizeof(int) >= 0, "int too small"); + int main(void) { + _Static_assert(sizeof(int) >= 1, "int too small"); + int ret = 0; + + _Static_assert(sizeof(int) >= 2, "int too small"); + + do { + _Static_assert(sizeof(int) >= 3, "int too small"); + } while (0); + + _Static_assert(sizeof(int) >= 4, "int too small"); + return ret; + } + ''', + 'HAVE__STATIC_ASSERT', + addmain=False, + strict=True, # -Werror + msg='Checking for _Static_assert') + conf.CHECK_HEADERS('linux/types.h crypt.h locale.h acl/libacl.h compat.h') conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h') conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h')