diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-04-08 11:43:12 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-04-08 11:43:12 -0700 |
| commit | b97b360c514acd0f5a148524a85bcdb583dbe914 (patch) | |
| tree | dc16900efcc7576ec5211f9c340e18bd01dd9020 /git-compat-util.h | |
| parent | 9d22ac51228304102deb62f30c3ecba6377e1237 (diff) | |
| parent | 5633aa3af1282cad5161174f17867399e58b2a54 (diff) | |
| download | git-b97b360c514acd0f5a148524a85bcdb583dbe914.tar.gz | |
Merge branch 'en/assert-wo-side-effects'
Ensure what we write in assert() does not have side effects,
and introduce ASSERT() macro to mark those that cannot be
mechanically checked for lack of side effects.
* en/assert-wo-side-effects:
treewide: replace assert() with ASSERT() in special cases
ci: add build checking for side-effects in assert() calls
git-compat-util: introduce ASSERT() macro
Diffstat (limited to 'git-compat-util.h')
| -rw-r--r-- | git-compat-util.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index cf733b38ac..f8562996ed 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1460,6 +1460,8 @@ extern int bug_called_must_BUG; __attribute__((format (printf, 3, 4))) NORETURN void BUG_fl(const char *file, int line, const char *fmt, ...); #define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__) +/* ASSERT: like assert(), but won't be compiled out with NDEBUG */ +#define ASSERT(a) if (!(a)) BUG("Assertion `" #a "' failed.") __attribute__((format (printf, 3, 4))) void bug_fl(const char *file, int line, const char *fmt, ...); #define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__) @@ -1592,4 +1594,11 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) */ #define NOT_CONSTANT(expr) ((expr) || false_but_the_compiler_does_not_know_it_) extern int false_but_the_compiler_does_not_know_it_; + +#ifdef CHECK_ASSERTION_SIDE_EFFECTS +#undef assert +extern int not_supposed_to_survive; +#define assert(expr) ((void)(not_supposed_to_survive || (expr))) +#endif /* CHECK_ASSERTION_SIDE_EFFECTS */ + #endif |
