Skip to content
Snippets Groups Projects
Commit e7f251fd authored by Nagy Tibor's avatar Nagy Tibor
Browse files

Fix assert when used as an expression

Based on what musl does.
parent bfa068df
No related branches found
No related tags found
1 merge request!172Fix assert when used as an expression
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
#define _BITS_ASSERT_H #define _BITS_ASSERT_H
#ifdef NDEBUG #ifdef NDEBUG
# define assert(cond) # define assert(cond) (void) 0
#else #else
# define assert(cond) if (!(cond)) { \ # define assert(cond) \
__assert(__func__, __FILE__, __LINE__, #cond); \ ((void)((cond) || (__assert(__func__, __FILE__, __LINE__, #cond), 0)))
}
#endif #endif
#endif #endif
...@@ -5,9 +5,12 @@ ...@@ -5,9 +5,12 @@
int main() { int main() {
assert(1 == 1); assert(1 == 1);
assert(1 + 1 == 2); assert(1 + 1 == 2);
puts("yay!"); puts("yay!");
if (assert(0 == 0), 1) {
puts("groovy!");
}
//This fails, but I can't test it because that'd //This fails, but I can't test it because that'd
//make the test fail lol //make the test fail lol
//assert(42 == 1337); //assert(42 == 1337);
......
yay! yay!
groovy!
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment