Git fork

git-compat-util: introduce ASSERT() macro

Create a ASSERT() macro which is similar to assert(), but will not be
compiled out when NDEBUG is defined, and is thus safe to use even if its
argument has side-effects.

We will use this new macro in a subsequent commit to convert a few
existing assert() invocations to ASSERT(). In particular, we'll
convert the handful of invocations which cannot be proven to be free of
side effects with a simple compiler/linker hack.

Signed-off-by: Elijah Newren <newren@gmail.com>
Acked-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Elijah Newren and committed by
Junio C Hamano
07fbc15c 683c54c9

+2
+2
git-compat-util.h
··· 1460 1460 __attribute__((format (printf, 3, 4))) NORETURN 1461 1461 void BUG_fl(const char *file, int line, const char *fmt, ...); 1462 1462 #define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__) 1463 + /* ASSERT: like assert(), but won't be compiled out with NDEBUG */ 1464 + #define ASSERT(a) if (!(a)) BUG("Assertion `" #a "' failed.") 1463 1465 __attribute__((format (printf, 3, 4))) 1464 1466 void bug_fl(const char *file, int line, const char *fmt, ...); 1465 1467 #define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)