diff options
| author | Enji Cooper <ngie@FreeBSD.org> | 2026-02-20 20:24:46 +0000 |
|---|---|---|
| committer | Enji Cooper <ngie@FreeBSD.org> | 2026-02-20 22:45:06 +0000 |
| commit | d1f1402dff63dd163d4ba4ac65f7f2ffd00c5e08 (patch) | |
| tree | 92df439d6a3930f9d7f40cae5f6888d8446da9d3 | |
| parent | e1886559ea477add82a0a86cddf728f6778f1603 (diff) | |
libnetbsd: import `__CTASSERT(..)` macros
These compile-time assert macros are similar to `Static_assert` on FreeBSD.
These macros are in use in newer versions of `contrib/netbsd-tests`.
Obtained from: https://github.com/NetBSD/src (c26cc77b3a0b26b95a2)
MFC after: 1 week
| -rw-r--r-- | lib/libnetbsd/sys/cdefs.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/libnetbsd/sys/cdefs.h b/lib/libnetbsd/sys/cdefs.h index fcc3cc6f15be..78c80735ad01 100644 --- a/lib/libnetbsd/sys/cdefs.h +++ b/lib/libnetbsd/sys/cdefs.h @@ -55,6 +55,22 @@ #define ___CONCAT(x,y) __CONCAT(x,y) /* + * Compile Time Assertion. + */ +#ifdef __COUNTER__ +#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__) +#else +#define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__) +#define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \ + __CONCAT(_,b)) +#endif +#define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z) +#define __CTASSERT1(x, y, z) \ + struct y ## z ## _struct { \ + unsigned int y ## z : /*CONSTCOND*/(x) ? 1 : -1; \ + } + +/* * The following macro is used to remove const cast-away warnings * from gcc -Wcast-qual; it should be used with caution because it * can hide valid errors; in particular most valid uses are in |
