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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user