Skip to content

Commit 07fbc15

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Acked-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 683c54c commit 07fbc15

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

git-compat-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,8 @@ extern int bug_called_must_BUG;
14601460
__attribute__((format (printf, 3, 4))) NORETURN
14611461
void BUG_fl(const char *file, int line, const char *fmt, ...);
14621462
#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.")
14631465
__attribute__((format (printf, 3, 4)))
14641466
void bug_fl(const char *file, int line, const char *fmt, ...);
14651467
#define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)

0 commit comments

Comments
 (0)