Date: Sat, 25 Apr 2026 16:32:33 +0000 From: Enji Cooper <ngie@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 7be895e50035 - stable/14 - libnetbsd: import `__CTASSERT(..)` macros Message-ID: <69ececa1.45160.4641cbd7@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by ngie: URL: https://cgit.FreeBSD.org/src/commit/?id=7be895e5003534e51efe37cc63a359219099bf4a commit 7be895e5003534e51efe37cc63a359219099bf4a Author: Enji Cooper <ngie@FreeBSD.org> AuthorDate: 2026-02-20 20:24:46 +0000 Commit: Enji Cooper <ngie@FreeBSD.org> CommitDate: 2026-04-25 16:32:25 +0000 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 (cherry picked from commit d1f1402dff63dd163d4ba4ac65f7f2ffd00c5e08) --- lib/libnetbsd/sys/cdefs.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/libnetbsd/sys/cdefs.h b/lib/libnetbsd/sys/cdefs.h index d0e06e46d241..e4ff4a516519 100644 --- a/lib/libnetbsd/sys/cdefs.h +++ b/lib/libnetbsd/sys/cdefs.h @@ -54,6 +54,22 @@ #define ___STRING(x) __STRING(x) #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 ithome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69ececa1.45160.4641cbd7>
