[PATCH v3 13/14] tools/nolibc: add __nolibc_static_assert()

Thomas Weißschuh posted 14 patches 1 month, 2 weeks ago
[PATCH v3 13/14] tools/nolibc: add __nolibc_static_assert()
Posted by Thomas Weißschuh 1 month, 2 weeks ago
Add a wrapper for _Static_assert() to use within nolibc.
While _Static_assert() itself was only standardized in C11,
in GCC and clang dialects it is also available in older standards.

Link: https://lore.kernel.org/lkml/20251203192330.GA12995@1wt.eu/
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/compiler.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
index c9ffd0496dae..a8c7619dcdde 100644
--- a/tools/include/nolibc/compiler.h
+++ b/tools/include/nolibc/compiler.h
@@ -63,4 +63,12 @@
 #  define __nolibc_clang_version 0
 #endif /* __clang__ */
 
+#if __STDC_VERSION__ >= 201112L || \
+	__nolibc_gnuc_version >= __nolibc_version(4, 6, 0) || \
+	__nolibc_clang_version >= __nolibc_version(3, 0, 0)
+#  define __nolibc_static_assert(_t) _Static_assert(_t, "")
+#else
+#  define __nolibc_static_assert(_t)
+#endif
+
 #endif /* _NOLIBC_COMPILER_H */

-- 
2.52.0

Re: [PATCH v3 13/14] tools/nolibc: add __nolibc_static_assert()
Posted by Willy Tarreau 1 month, 2 weeks ago
Hi Thomas,

On Sat, Dec 20, 2025 at 02:55:57PM +0100, Thomas Weißschuh wrote:
> Add a wrapper for _Static_assert() to use within nolibc.
> While _Static_assert() itself was only standardized in C11,
> in GCC and clang dialects it is also available in older standards.
> 
> Link: https://lore.kernel.org/lkml/20251203192330.GA12995@1wt.eu/
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  tools/include/nolibc/compiler.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
> index c9ffd0496dae..a8c7619dcdde 100644
> --- a/tools/include/nolibc/compiler.h
> +++ b/tools/include/nolibc/compiler.h
> @@ -63,4 +63,12 @@
>  #  define __nolibc_clang_version 0
>  #endif /* __clang__ */
>  
> +#if __STDC_VERSION__ >= 201112L || \
> +	__nolibc_gnuc_version >= __nolibc_version(4, 6, 0) || \
> +	__nolibc_clang_version >= __nolibc_version(3, 0, 0)
> +#  define __nolibc_static_assert(_t) _Static_assert(_t, "")
> +#else
> +#  define __nolibc_static_assert(_t)
> +#endif
> +

Yeah, that's clean this way, I like it!

Acked-by: Willy Tarreau <w@1wt.eu>