]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/replace: add BUILD_ASSERT()
authorStefan Metzmacher <metze@samba.org>
Wed, 4 Mar 2026 15:39:10 +0000 (16:39 +0100)
committerRalph Boehme <slow@samba.org>
Tue, 4 Aug 2026 09:51:32 +0000 (09:51 +0000)
This uses _Static_assert() from C11...

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/replace/replace.h
lib/replace/wscript

index 78f44a8878a0120c7daf010043f6df5317567e40..538d1f45b271a7b9bd7851c57dda60c51e556a47 100644 (file)
@@ -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);
index 4621d90a70a562452870638f9daee1880c01dae0..be2a6ae674f3ddcf742d16d737c1e665ce3f3f17 100644 (file)
@@ -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')