From 09dbac0b2a3816f3e2b70604374e57dc2e690f33 Mon Sep 17 00:00:00 2001 From: Maxime Henrion Date: Thu, 16 Jul 2026 12:18:17 -0400 Subject: [PATCH] DEBUG: add BUG_ON_STATIC(): a compile-time BUG_ON() Fails the build when , a constant expression, is true. Maps to _Static_assert() on C11+; older dialects declare a negatively-sized extern array instead, which emits no storage nor symbol. Usable at file and block scope. --- include/haproxy/bug.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 32db432fb..bb1fc0147 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -439,6 +439,15 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S # define BUG_ON_STRESS(cond, ...) do { } while (0) #endif +/* BUG_ON_STATIC(cond): fail the build if is true. */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#define BUG_ON_STATIC(cond) \ + _Static_assert(!(cond), "bug condition \"" #cond "\" matched") +#else +#define BUG_ON_STATIC(cond) \ + extern char CONCAT(bug_on_static_, __LINE__)[(cond) ? -1 : 1] __maybe_unused +#endif + /* When not optimizing, clang won't remove that code, so only compile it in when optimizing */ #if defined(__GNUC__) && defined(__OPTIMIZE__) #define HA_LINK_ERROR(what) \ -- 2.47.3